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:[EMAIL PROTECTED]]
Sent: Friday, February 22, 2002 4:46 AM
To: [EMAIL PROTECTED]
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