ID:               44590
 User updated by:  vituko at gmail dot com
 Reported By:      vituko at gmail dot com
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Debian GNU/Linux
 PHP Version:      5.3CVS-2008-04-01 (CVS)
 New Comment:

The situation with methods is easier : one private method (static or 
not) can exclusively be accessed from the same context (class body) 
where it was declared.

I think it is more powerfull the other way : when a class declares a 
method should can invoque it on an object of an inherited class.


Previous Comments:
------------------------------------------------------------------------

[2008-04-01 12:19:50] vituko at gmail dot com

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44590&edit=1

Reply via email to