2009-07-20 00:31:43 +08:00
|
|
|
--TEST--
|
|
|
|
Testing call_user_func() with closures
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$foo = function() {
|
2020-02-04 05:52:20 +08:00
|
|
|
static $instance;
|
2018-09-17 01:16:42 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
if (is_null($instance)) {
|
|
|
|
$instance = function () {
|
|
|
|
return 'OK!';
|
|
|
|
};
|
|
|
|
}
|
2018-09-17 01:16:42 +08:00
|
|
|
|
2020-02-04 05:52:20 +08:00
|
|
|
return $instance;
|
2009-07-20 00:31:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var_dump(call_user_func(array($foo, '__invoke'))->__invoke());
|
|
|
|
var_dump(call_user_func(function() use (&$foo) { return $foo; }, '__invoke'));
|
|
|
|
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
2016-11-23 05:12:07 +08:00
|
|
|
string(3) "OK!"
|
2009-07-20 00:31:43 +08:00
|
|
|
object(Closure)#%d (1) {
|
2016-11-23 05:12:07 +08:00
|
|
|
["static"]=>
|
2009-07-20 00:31:43 +08:00
|
|
|
array(1) {
|
2016-11-23 05:12:07 +08:00
|
|
|
["instance"]=>
|
2009-07-20 00:31:43 +08:00
|
|
|
object(Closure)#%d (0) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|