Re: [PHP-PEAR] indirect function call
[email protected] (Kendrick Vargas)
| Newsgroups | php.pear |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 14 Feb 2001, Jesse Swensen wrote: > on 2/14/01 9:39 AM, Burak DAYIOGLU at [email protected] wrote: > > > We are having a little problem with indirect function calls as being > > discussed on the list for a while... The below thingie does not work, > > does anybody have any idea to make it run? > > > > <?php > > > > class bdd > > { > > var $bdd_var; > > function bdd_function($input) > > { > > echo "This is bdd_function speaking and the input is : > > $input"; > > } > > } > > > > $foo = new bdd; > > $bar = $foo->bdd_function; > > $bar("foo bar !"); > > ?> > > I believe you will have to eval the string, i.e. eval("$bar('foo bar !')"); no, eval'ing isn't particularly good cuz it'll truely mangle arrays (it'll actually pass the string "Array" to the function if it hits an array). The problem is in your syntax. Why not try: $foo = new bdd; $bar = bdd_function; $foo->{$bar}("foo bar !"); In the original example, you are basically assigning the contents of the variable $foo->bdd_function to the variable $bar. If you really wanna try the original way, you could try something like: $foo = new bdd; $bar = "\$foo->bdd_function"; $bar("foo bar !"); but I have no idea if that'll work. -peace --- BEGIN GEEK CODE BLOCK ----------+---------- GAT d- s:+ !a C++$ UL/S/I/B++++$ P+ | "In the ongoing battle between objects L++ E- W+(+++) N K- w(---) O-- M@ | made of aluminum going hundreds of V(--) PS+++ PE Y+ PGP@ t++ 5 X+ R- | miles per hour and the ground going tv+ b- DI++++ D+(+++) G e>++ h--- | zero, the ground has yet to lose." r++ z+>+++ - END GEEK CODE BLOCK ---+