#50822 [NEW]: Private instance variable visibile for new instance created within an object

From: Date: Fri, 22 Jan 2010 12:45:37 +0000
Subject: #50822 [NEW]: Private instance variable visibile for new instance created within an object
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146865@lists.php.net to get a copy of this message
From: aron at zajlik dot hu Operating system: Mac OS X PHP version: 5.3.1 PHP Bug Type: Scripting Engine problem Bug description: Private instance variable visibile for new instance created within an object 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 bug report at http://bugs.php.net/?id=50822&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50822&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50822&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50822&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50822&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50822&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50822&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50822&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50822&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50822&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50822&r=support Expected behavior: http://bugs.php.net/fix.php?id=50822&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50822&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50822&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50822&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50822&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50822&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50822&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50822&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50822&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50822&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50822&r=mysqlcfg

« previous php.bugs (#146865) next »