Re: function by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?php
function foo { echo "Hi";}
$bar = 'foo';
$bar();
?>

On Sun, April 9, 2006 1:17 pm, tedd wrote:
> 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
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux