|
Posted by maxlego on 09/27/50 11:17
Hi!
I am trying to dynamically create a new member function to my class. I
have come up with this piece of code. It almost looks as if it adds the
member functions to the class. But when trying to call them, nothing
happens. Is this possible at all?
I am trying to do this thing because all the mmeber functions would have
similar functionality except names. Since there are no facilities like
C preprocessor I thought that eval might help.
I am using PHP5 ...
class X
{
function X()
{
$this->mkMember('foo');
$this->mkMember('bar');
}
function mkMember($name)
{
$s = "function $name(\$x) { echo 'sadf'; }";
eval($s);
}
}
$a = new X();
$a->foo(11);
$a->bar(1.2 , 3,4,5);
--
maxlego
Navigation:
[Reply to this message]
|