jphp
jphp copied to clipboard
Cannot call closure returned by bindTo
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
Workaround:
class a {
public static function init() { var_dump("test"); }
}
((function () {
static::init();
})->bindTo(null, a::class))();