| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [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 ?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 05:00:01 2025 UTC | 
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