|
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]
|