I am wondering if there is any way to pass a funtion as a object or some how exectute the contents of a variable as a function. This is an object orientation issue and am not sure if php has enough OO features to support this but heres what I want to do.
class ExampleClass
{
var $mDieMethod = '';
function DoSomething($this_test_fails=0)
{
if(! $this_test_fails)
{
$this->Die('Error');
}
}
function Die($msg)
{
if(! $this->mDieMethod)
{
die($msg);
}
else
{
$this->mDieMethod($msg);
}
}
function SetDieMethod($dieMethod)
{
$this->mDieMethod = $dieMethod;
}
}
function custom_die_method($msg)
{
print '<h1>BIG ERROR</h1>';
print "<h2>$msg</h2>";
exit(1);
}
$example = new ExampleClass();
$example->SetDieMethod( custom_die_method() );
$example->DoSomething();
So as you can see I am trying to pass a function to be called by another function. But what happens is that php executes the custom function and passes the result of that
function rather than the function itself.
At one time I think there was a way to set a variable to a function name and then call the function sorta like this:
$function_var = 'custom_die_method';
execute($function_var);
But I don't remember how to do that. Either way I would appreciate feed back about both methods.
thanks
-ruach