|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77154 private property inheritance discussion
Submitted: 2018-11-14 18:42 UTC Modified: 2019-01-27 04:22 UTC
From: Assigned: dmitry (profile)
Status: No Feedback Package: Class/Object related
PHP Version: master-Git-2018-11-14 (Git) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2018-11-14 18:42 UTC]
This behavior is wether right or wrong ; let's debate :

Test script:
class A {
	private static $foo = 'Afoo';
	function foo() { return static::$foo; }

class B extends A { }

$b = new B;
echo $b->foo();

Expected result:
PHP <= 7.3 shows :

Fatal error: Uncaught Error: Cannot access  property B::$foo in XXXX

PHP-master shows :

the string 'Afoo'

Actual result:
What should be the right behavior ?

Considering that the same use-case using non-static attribute, and non static classic $this accesses the attributes just all right in all PHP versions

Should private static attributes be inherited, or not ?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-15 10:40 UTC]
This issue might better be discussed on internals@.
 [2018-11-15 10:51 UTC]
-Assigned To: +Assigned To: dmitry
 [2018-11-15 10:51 UTC]
@dmitry: What do you think about this? This is a side-effect of the changes to shadow/private property handling.
 [2019-01-14 12:49 UTC]
-Status: Assigned +Status: Feedback
 [2019-01-14 12:49 UTC]
Despite, this behavior change was unintended, I think, the new static properties visibility rules are more consistent with regular object properties.

class A {
	private $foo = 'foo';
	static private $bar = 'bar';
	function foo() {
	static function bar() {

class B extends A { }

$b = new B;
$b->foo(); // works
B::bar();  // didn't work before master
 [2019-01-27 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 13:01:28 2024 UTC