From: jay at jay dot cz Operating system: ubuntu linux PHP version: 5.2.10 PHP Bug Type: Class/Object related Bug description: private var accessible from static class
Description: ------------ Private property of initialized class, is accessible from static version of the same class. Reproduce code: --------------- class FOO { private $bar = 0; private static $instance = false; public static function get_instance(){ if(self::$instance === false) self::$instance = new FOO; return self::$instance; } public static function set_bar( $b ){ $foo = FOO::get_instance(); $foo->bar = $b; } public static function dump_bar(){ $foo = FOO::get_instance(); echo $foo->bar; } } FOO::set_bar( 1 ); FOO::dump_bar(); $foo = FOO::get_instance(); echo $foo->bar; Expected result: ---------------- Fatal error: Cannot access private property FOO::$bar in /var/www/index.php on line 10 I should not be able to write to a private property from "outside". (Even thou it's the same code for both classes (static and initialized).) Actual result: -------------- 1 Fatal error: Cannot access private property FOO::$bar in /var/www/index.php on line 20 Well, I can write to the private property and I can read it, from inside the static. The error is when I try to access it from completely "outside". And that error is correct. Same result for private and protected. -- Edit bug report at http://bugs.php.net/?id=49121&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49121&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49121&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49121&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49121&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49121&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49121&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49121&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49121&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49121&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49121&r=support Expected behavior: http://bugs.php.net/fix.php?id=49121&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49121&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49121&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49121&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49121&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49121&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49121&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49121&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49121&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49121&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49121&r=mysqlcfg