Sła*_*dła 4 php this anonymous-function
如何在没有这个的情况下在类中声明一个函数?
<?php
class modul {
var $i=1;
var $j=1;
public function init(){
$test1 = function($vRecord){
return 'zwrot';
};
echo "<pre>";
print_r($test1);
echo "</pre>";
}
}
$modul = new modul();
$modul->init();
Run Code Online (Sandbox Code Playgroud)
我打印时的结果:
Closure Object
(
[this] => modul Object
(
[i] => 1
[j] => 1
)
[parameter] => Array
(
[$vRecord] =>
)
)
Run Code Online (Sandbox Code Playgroud)
如何在没有键的情况下传递函数:'this'?我想要一个纯函数 print_r 和这样的结果:
代码:
<?php
$test2 = function($vRecord){
return 'zwrot';
};
echo "<pre>";
print_r($test2);
echo "</pre>";
Run Code Online (Sandbox Code Playgroud)
我打印时的结果:
Closure Object
(
[parameter] => Array
(
[$vRecord] =>
)
)
Run Code Online (Sandbox Code Playgroud)
您可以定义静态匿名函数:
$test1 = static function($vRecord){
return 'zwrot';
};
Run Code Online (Sandbox Code Playgroud)