Bug #77154 [Fbk->NoF]: private property inheritance discussion

From: Date: Sun, 27 Jan 2019 04:22:04 +0000
Subject: Bug #77154 [Fbk->NoF]: private property inheritance discussion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219226@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77154&edit=1 ID: 77154 Updated by: php-bugs@lists.php.net Reported by: jpauli@php.net Summary: private property inheritance discussion -Status: Feedback +Status: No Feedback Type: Bug Package: Class/Object related Operating System: * PHP Version: master-Git-2018-11-14 (Git) Assigned To: dmitry Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2019-01-14 12:49:10] 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 ------------------------------------------------------------------------ [2018-11-15 10:51:26] nikic@php.net @dmitry: What do you think about this? This is a side-effect of the changes to shadow/private property handling. ------------------------------------------------------------------------ [2018-11-15 10:40:19] cmb@php.net This issue might better be discussed on internals@. ------------------------------------------------------------------------ [2018-11-14 18:42:56] 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 ? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77154&edit=1

« previous php.bugs (#219226) next »