Re: [PHP] Dynamic Function with return?
This code works. It calls the function and receives the appropriate return value. But, is there a better way of doing this? It seems a bit round-a-bout. Two options, details in the manual: call_user_func() or create_function(). - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Function with return?
Sample Code: // ?PHP // version 4.3.6 function testFunction($foo) { return $foo==TEST; } function wrapper($foofunc, $foovar) { return eval(return $foofunc($foovar);); } echo wrapper(testFunction, TEST); ? // This code works. It calls the function and receives the appropriate return value. But, is there a better way of doing this? It seems a bit round-a-bout. Thanks!
Re: [PHP] Dynamic Function with return?
1 way is here.You can use object OOP. --- bskolb [EMAIL PROTECTED] wrote: Sample Code: // ?PHP // version 4.3.6 function testFunction($foo) { return $foo==TEST; } function wrapper($foofunc, $foovar) { return eval(return $foofunc($foovar);); } echo wrapper(testFunction, TEST); ? // This code works. It calls the function and receives the appropriate return value. But, is there a better way of doing this? It seems a bit round-a-bout. Thanks! = -DIGITAL SIGNATURE--- ///Mohsen Pahlevanzadeh Network administrator programmer My home phone is: +98213810146 My email address is m_pahlevanzadeh at yahoo dot com My website is: http://webnegar.net __ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SOLVED RE: [PHP] Dynamic Function with return?
Thanks for the quick reply, I wasn't aware that passing a variable for the object would work. New code: class testClass { function testFunction($foo) { return $foo==TEST; } } $testObj = new testClass; $testFunc = testFunction; echo $testObj-$testFunc(TEST); -Original Message- From: Pahlevanzadeh Mohsen [mailto:[EMAIL PROTECTED] Sent: Friday, August 27, 2004 7:24 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP] Dynamic Function with return? 1 way is here.You can use object OOP. --- bskolb [EMAIL PROTECTED] wrote: Sample Code: // ?PHP // version 4.3.6 function testFunction($foo) { return $foo==TEST; } function wrapper($foofunc, $foovar) { return eval(return $foofunc($foovar);); } echo wrapper(testFunction, TEST); ? // This code works. It calls the function and receives the appropriate return value. But, is there a better way of doing this? It seems a bit round-a-bout. Thanks! = -DIGITAL SIGNATURE--- ///Mohsen Pahlevanzadeh Network administrator programmer My home phone is: +98213810146 My email address is m_pahlevanzadeh at yahoo dot com My website is: http://webnegar.net __ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Function with return?
-Original Message- From: bskolb [mailto:[EMAIL PROTECTED] Sent: Friday, August 27, 2004 3:59 PM To: [EMAIL PROTECTED] Subject: [PHP] Dynamic Function with return? Sample Code: // ?PHP // version 4.3.6 function testFunction($foo) { return $foo==TEST; } function wrapper($foofunc, $foovar) { return eval(return $foofunc($foovar);); } echo wrapper(testFunction, TEST); ? // This code works. It calls the function and receives the appropriate return value. But, is there a better way of doing this? It seems a bit round-a-bout. Did you already try this? function wrapper($foofunc, $foovar){ return $foofunc($foovar); } http://us3.php.net/manual/en/functions.variable-functions.php Maybe I'm missing something, but I don't see the need for the eval since PHP supports variable function names. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php