Bug #77154 [Asn->Fbk]: private property inheritance discussion
Edit report at https://bugs.php.net/bug.php?id=77154&edit=1
ID: 77154
Updated by: dmitry@php.net
Reported by: jpauli@php.net
Summary: private property inheritance discussion
-Status: Assigned
+Status: Feedback
Type: Bug
Package: Class/Object related
Operating System: *
PHP Version: master-Git-2018-11-14 (Git)
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)