3

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();
1
  • That's not even workable code to test. Commented Dec 18, 2015 at 19:50

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.