I can assign a function to a class variable in PHP, i.e. to $this->variable
.
However, when I try to execute the function, it fails with:
FATAL ERROR Call to undefined method a::f()
Here is a snippet to illustrate the problem:
<?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()
}
}