Re: Re: dynamic object instances

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux