I'm hoping to create a variable that could contain either a function or a class method...
function foo($arg)
{
echo "this is a FUNCTION, the arg =" . $arg;
}
class bar
{
function foo($arg)
{
echo "this is a METHOD, the arg =" . $arg;
}
}
This works great with the function...
$variable = 'foo';
$variable('test 1');
// outputs
this is a FUNCTION, the arg = test 1
This works but you have to explicity call add the object prefix before the method variable and I don't want to do that.
$obj = new bar;
$variable = 'foo';
$obj->$variable('test 2');
// outputs
this is a METHOD, the arg = test 2
This also works, but is even less practical.
$obj = new bar;
$variable = array(& $obj, 'foo');
$variable[0]->$variable[1]('test 3');
// outputs
this is a METHOD, the arg = test 3
This is what I'd like to do (which dosen't work)
$obj = new bar;
$variable = $obj->foo;
$variable('test 4');
This sort of thing would do and it works when setting call-back functions/methods with some prebuild functions (such as array_walk or session_set_save_handlers). But not with variables 8(
$obj = new bar;
$variable = array(& $obj, 'foo');
$variable('test 5');