Re: function by reference

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

 



On Monday 10 April 2006 19:19, Richard Lynch wrote:
> 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

I believe you're thinking more of the C++ style of returning by reference.  
This article should help explain how references work, and how to return 
references... most specifically check the "Returning References" section.

http://www.php.net/manual/en/language.references.php

HTH
-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

-- 
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