PHP 内部没有 this 的匿名函数
PHP anonymous function without this inside
如果没有这个,如何在 class 中声明一个函数?
<?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();
我打印时的结果:
Closure Object
(
[this] => modul Object
(
[i] => 1
[j] => 1
)
[parameter] => Array
(
[$vRecord] =>
)
)
如何在没有密钥的情况下传递函数:'this'?我想要 print_r 中的纯函数,结果如下:
代码:
<?php
$test2 = function($vRecord){
return 'zwrot';
};
echo "<pre>";
print_r($test2);
echo "</pre>";
我打印的结果:
Closure Object
(
[parameter] => Array
(
[$vRecord] =>
)
)
你可以定义一个Static anonymous function:
$test1 = static function($vRecord){
return 'zwrot';
};
如果没有这个,如何在 class 中声明一个函数?
<?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();
我打印时的结果:
Closure Object
(
[this] => modul Object
(
[i] => 1
[j] => 1
)
[parameter] => Array
(
[$vRecord] =>
)
)
如何在没有密钥的情况下传递函数:'this'?我想要 print_r 中的纯函数,结果如下:
代码:
<?php
$test2 = function($vRecord){
return 'zwrot';
};
echo "<pre>";
print_r($test2);
echo "</pre>";
我打印的结果:
Closure Object
(
[parameter] => Array
(
[$vRecord] =>
)
)
你可以定义一个Static anonymous function:
$test1 = static function($vRecord){
return 'zwrot';
};