ID: 50822 Updated by: [email protected] Reported By: aron at zajlik dot hu -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Mac OS X PHP Version: 5.3.1 New Comment:
Ever heard of "singleton" ? Also: http://php.net/manual/en/language.oop5.patterns.php So yes, this is expected and correct behaviour. Previous Comments: ------------------------------------------------------------------------ [2010-01-22 12:45:36] aron at zajlik dot hu Description: ------------ I found a situation which to me seems like unexpected behavior. I private variable (as far as I know) should only be accessible within the object itself, and not by the "outside world". Yet this becomes a bit confusing once the object is created within an instance of itself. Is this a bug or is this expected behavior? Reproduce code: --------------- <? class Test{ private $variable = "asdf"; static function create_a_test(){ $tobj = new Test(); echo $tobj->variable; // Works! (which it shouldn't?!?) } } $my_test = new Test(); //echo $my_test->variable; // Returns Fatal error: Cannot access private property (which it should!) $my_test->create_a_test(); ?> Expected result: ---------------- I would expect the above code NOT to return the private variable on line 7. Actual result: -------------- The private variable can be accessed without a problem. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50822&edit=1
