【发布时间】:2019-07-21 02:33:39
【问题描述】:
我可以将函数分配给 PHP 中的类变量,即$this->variable。
但是,当我尝试执行该函数时,它失败了:
FATAL ERROR Call to undefined method a::f()
这里有一个sn-p来说明问题:
<?php
new a();
class a
{
private $f;
function __construct()
{
$g = function() { echo "hello g"; };
$g(); //works
$this->f = function() { echo "hello f"; };
$this->f(); //FATAL ERROR Call to undefined method a::f()
}
}
【问题讨论】:
标签: php php-7 anonymous-function php-5.6 php-5.4