here is an example class:
public class example
{
private $foof;
public function __construct()
{
$this->foof = $this->foo;
}
public function foo($val=0)
{
// do something...
}
}
So basically, in the constructer of the sample code, is it possible to assign a class method to a variable?
Ultimately what i want is to have an associative array with all the class methods aliased in it…that possible in php?
In PHP5.3+ (which you should be using anyway!) you can simply create an anonymous function which calls your method:
However, you cannot call it using
$this->foof()– you have to assign it to a variable first:$foof = $this->foof; $foof();In older PHP versions you cannot easily do this –
create_function()does not create a closure so$thisis not available there.