Late static binding behaves differently in PHP 5.3 and PHP 5.4

From: Date: Thu, 24 Jan 2013 17:57:12 +0000
Subject: Late static binding behaves differently in PHP 5.3 and PHP 5.4
Groups: php.general 
Request: Send a blank email to php-general+get-320100@lists.php.net to get a copy of this message
Hello everybody, I found a difference between late static binding in PHP 5.3 and PHP 5.4 and I cannot find any documentation to explain this difference. Here is some code to show you this difference: class Foo { const MY_CONST = 'The Foo'; static $my_var = self::MY_CONST; } class Bar extends Foo { const MY_CONST = 'The Bar'; static $my_var = self::MY_CONST; } echo Bar::$my_var."\n"; echo Foo::$my_var."\n"; In PHP 5.3 (tested on 5.3.2), the output is: The Bar The Foo In PHP 5.4 (tested on 5.4.4 and 5.4.6), the output is: The Bar The Bar It's confusing me, is this a bug or a feature? Note all in both versions, the output is same if you call Foo before Bar: echo Foo::$my_var."\n"; echo Bar::$my_var."\n"; Output in PHP 5.3 and PHP 5.4: The Foo The Bar This is even more confusing for me since the result is not the same in PHP 5.4 base on the statement you execute first... Keven.

« previous php.general (#320100) next »