RE: [PHP] Re: Creating methods runtime
| From: | Martin Towell | Date: | Thu, 21 Feb 2002 23:46:41 +0000 |
| Subject: | RE: [PHP] Re: Creating methods runtime | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-85790@lists.php.net to get a copy of this message | ||
dunno about using eval() but this worked - not as elegant as I'd want it,
but it works
class test
{
function user_func($f, $a, $b) { $z = $this->$f; return ($z ? $z($a, $b)
: null); }
}
$blah = new test;
$blah->new_func = create_function('$a,$b', 'return $a+$b;');
echo $blah->user_func("new_func", 3, 4);
echo $blah->user_func("none", 3, 4);
HTH
Martin
-----Original Message-----
From: Matthew J Gray [mailto:matthew.j.gray@uwrf.edu]
Sent: Friday, February 22, 2002 4:46 AM
To: php-general@lists.php.net
Subject: [PHP] Re: Creating methods runtime
No there really isn't. I wrote an extension that does it for me, but
I am waiting to see what the second zend engine will have for this
rather that using my hack. Maybe check the Zend Engine 2 mailing list
to see what the future may hold.
Matt
Mika Tuupola wrote:
>
> Is there a way to create/add methods runtime to a class via
> constructor or static factory method? I know it is possible
> to create functions runtime using eval() or create_function()
> but I havent been able to make them appear as methods for
> a class.
>
> --
> Mika Tuupola
> http://www.appelsiini.net/~tuupola/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php