Reply to Re: [PHP] Re: dynamic object instances

Your name:

Reply:


Posted by Eli on 08/11/05 04:51

Thomas Angst wrote:
> Thanks for you answer, but sorry, I do not understand your hint. I tried
> this code:
> class test {
> var $txt;
> function test($txt) { $this->txt = $txt; }
> function out() { echo $this->txt; }
> }
> $obj = call_user_func_array(array('test', 'test'), array('foobar'));
> $obj->out();
> But I'm getting an error while accessing the $this pointer in the
> constructor.

This will not work, since it is like calling a static class method, and
$this is not allowed to be used in static methods.

I solved this with eval() function.
<?
$obj_eval="return new $class(";
for ($i=0; $i<count($args); $i++)
$obj_eval.="\$args[$i],";
$obj_eval=substr($obj_eval,0,-1).");";
$obj=eval($obj_eval);
?>

[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

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