You are here: Re: [PHP] Re: dynamic object instances « PHP « IT news, forums, messages
Re: [PHP] Re: dynamic object instances

Posted by Thomas Angst on 08/11/05 00:02

Matthew Weier O'Phinney schrieb:

>Use the func_* functions, along with array_shift(). In addition, you'll
>need to use either a standard-named static instantiator, or the class
>name as the constructor method:
>
>function create($class) {
> $args = func_get_args();
> array_shift($args); // remove $class from the args list
>
> // Do this if using a standard-named static instantiator method
> // across classes; in this case 'init':
> return call_user_func_array(array($class, 'init'), $args);
>
> // Or use a function named after the class name as the instantiator
> // method (ala PHP4):
> return call_user_func_array(array($class, $class), $args);
>}
>
>
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.

Thomas

 

Navigation:

[Reply to this 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

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