php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44590 strange behavior of visibility
Submitted: 2008-04-01 12:19 UTC Modified: 2008-04-01 18:06 UTC
From: vituko at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3CVS-2008-04-01 (CVS) OS: Debian GNU/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vituko at gmail dot com
New email:
PHP Version: OS:

 

 [2008-04-01 12:19 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-01 16:32 UTC] vituko at gmail dot com
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.
 [2008-04-01 18:06 UTC] vituko at gmail dot com
Sorry, this report is bogus.
I misunderstood the results I got.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC