如何将函数作为参数传递给类,然后将其分配给本地类的 var!
这是我的情况,可以解决吗?
<?php
class a {
protected $var;
function __construct($fun) {
echo $fun('world'); // This is working perfect
$this->var = $fun;
}
function checkit($x) {
return $this->var($x); // This is not working [ Call to undefined method a::var() ]
}
}
$mth = 'mathm';
$cls = new a(&$mth); // result [ hello (world) ]
echo $cls->checkit('universe'); // <- not working as it fail
function mathm($i) {
return 'hello (' . $i . ')';
}
?>