Reply to how to dynamically create member functions

Your name:

Reply:


Posted by maxlego on 10/10/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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация