php.net |  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: jpauli@php.net 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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-11-14 18:42 UTC] jpauli@php.net
Description:
------------
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 ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-15 10:40 UTC] cmb@php.net
This issue might better be discussed on internals@.
 [2018-11-15 10:51 UTC] nikic@php.net
-Assigned To: +Assigned To: dmitry
 [2018-11-15 10:51 UTC] nikic@php.net
@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] dmitry@php.net
-Status: Assigned +Status: Feedback
 [2019-01-14 12:49 UTC] dmitry@php.net
Despite, this behavior change was unintended, I think, the new static properties visibility rules are more consistent with regular object properties.

<?php
class A {
	private $foo = 'foo';
	static private $bar = 'bar';
	function foo() {
		var_dump($this->foo);
	}
	static function bar() {
		var_dump(static::$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: Fri Apr 19 03:01:27 2024 UTC