Late static binding behaves differently in PHP 5.3 and PHP 5.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux