|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-01-22 14:38 UTC] jani@php.net
[2010-01-22 15:16 UTC] aron at zajlik dot hu
[2010-01-22 22:51 UTC] degeberg@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Feb 19 14:00:01 2026 UTC |
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.