jphp icon indicating copy to clipboard operation
jphp copied to clipboard

Cannot call closure returned by bindTo

Open danog opened this issue 5 years ago • 1 comments

Closures returned by bindTo cannot be directly called.

Source:

class a {
    public static function init() { var_dump("test"); }
}

(function () {
    static::init();
})->bindTo(null, a::class)();

Result:

[daniil@daniil-arch jav]$ php src/q.php 
string(4) "test"

[daniil@daniil-arch jav]$ jppm start
-> linux
-> app:run 
-> install 

Fatal error: Uncaught ParseError: Syntax error, unexpected 'function' in res://q.php on line 6, position 2
Stack Trace:
#0 {main}
  thrown in res://q.php on line 6

Storing the return value of bindTo in a variable and calling that works just fine

danog avatar Mar 09 '20 13:03 danog

Workaround:

class a {
    public static function init() { var_dump("test"); }
}

((function () {
    static::init();
})->bindTo(null, a::class))();

dim-s avatar Mar 10 '20 15:03 dim-s