Re: Late static binding behaves differently in PHP 5.3 and PHP 5.4

From: Date: Thu, 24 Jan 2013 18:25:17 +0000
Subject: Re: Late static binding behaves differently in PHP 5.3 and PHP 5.4
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-320101@lists.php.net to get a copy of this message
Hi Keven, First, I don't see any late static binding being used here. LSB only applies when you access a static member using the static keyword within a class method. This code uses static properties but accesses them directly without going through class methods. Here's an example of LSB: class Foo { static $my_var = 'The Foo'; static function dump() { echo static::$my_var . "\n"; // Use Foo's or Bar's depending on what appears before ::dump() } } class Bar extends Foo { static $my_var = 'The Bar'; } Bar::dump(); // The Bar Foo::dump(); // The Foo Here Foo::dump() uses LSB to pick the source of $my_var. That being said, what you're seeing does look like a change (or bug) in how PHP accesses constants. Given that it is order-dependent, my guess is that 5.4 introduced a bug that causes Bar to push its constant up into Foo. The strange thing is that the constant is compiled into the class, and since Bar extends Foo I would expect Foo to be compiled first regardless of the order in which you access the static variable later. David

« previous php.general (#320101) next »