Code on the local machine works good, but strange on the remote server. PHP 5.5.9 on the remote server, PHP 5.5.28 on the local machine what can be the reason of such a strange behaviour on the remote server (PHP version, server configuration, ...) ?
class A {
...
public static f1(){
...
self::$f2 = static::f2();
...
}
...
protected static function f2() {
...
var_dump(static::class); // returns B on the local machine and on the remote server
$f3 = function () {
var_dump(static::class); // returns B on the local machine and returns A on the remote server
...
$data = static::f4() ...
...
};
...
}
...
}
class B extends A{...}
...
self::$B = B::f1();
This is a known bug that was fixed in PHP 5.5.14. Below is a quote from the original bug report:
Closures do not correctly capture the late bound class (static::) in some cases
Description:
When a PHP closure is created, it is supposed to capture the late bound class of the enclosing function. There are a number of cases involving derived classes and static methods or static closures (or both) where it doesn't work correctly.
The test script I've included demonstrates the problem. I've tested it on PHP 5.6.0alpha1, but I can also reproduce the problem on various builds of PHP 5.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With