Hi gang:

Not that I have an immediate need for this, but in other languages one can access a function by reference (in other words, it's address -- such as call(function address) ).

In php, one can pass a variable by reference by simply using the ampersand, such a &$a.

Is there a similar way to reference a function?

Rob, was kind enough to post the following code, but I was looking for something where I could store the function's address in a variable. Something like:

$a = &f_a();

And then, where I could use call_user_func($a); (or something similar) and the function would do it's thing -- anything like that?

Thanks

tedd

--- Rob's suggestion follows.

Like the following?

<?php

function f_a()
{
    echo 'a';
}

function f_b()
{
    echo 'b';
}

function f_c()
{
    echo 'c';
}

$map = array
(
    'a' => 'f_a',
    'b' => 'f_b',
    'c' => 'f_c',
);

$map['a']();
$map['b']();
$map['c']();

?>


--
--------------------------------------------------------------------------------
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to