|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-31 14:13 UTC] jay at jay dot cz
[2009-07-31 23:32 UTC] jani@php.net
[2009-08-08 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
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.