|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-04-01 16:32 UTC] vituko at gmail dot com
[2008-04-01 18:06 UTC] vituko at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 06:00:01 2025 UTC |
Description: ------------ Context visibility of inherited private attributes when they apply to child classes. When a private attribtue is inherited, it's still accessible from the context (base class) where it was declared and it becomes accessible from the child context (unidirectional visibility). But when this attribute is static (class attribute), it becomes inaccessible from every context : the base class and the child class. I don't know if it's the normal behavior, anyway I find it strange and it could be documented. Thanks Reproduce code: --------------- class a { private $v ; private static $w ; function f($c) { $c -> v = 'asdf' ; $c :: $w = 'fdsa' ; } } class b extends a { function g($c) { $c -> v = 'asdf' ; $c :: $w = 'fdsa' ; } } $a = new a() ; $b = new b() ; $a-> f($a) ; $a-> f($b) ; $b -> f($b) ; $b -> g($b) ; Expected result: ---------------- no errors Actual result: -------------- A - protected static $w ; all is ok B - private static $w ; 1 : $a-> f($a) ; -> ok 2 : $a-> f($b) ; -> Cannot access property b::$w 3 : $b -> f($b) ; -> Cannot access property b::$w 4 : $b -> g($b) ; -> Cannot access property b::$w 2,3,4 : b:$w is accessible from nowhere. The errors are not : - Access to undeclared static property - Cannot access private property