Re: Re: dynamic object instances

From: Date: Wed, 10 Aug 2005 21:02:46 +0000
Subject: Re: Re: dynamic object instances
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-220374@lists.php.net to get a copy of this message
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

« previous php.general (#220374) next »