I am trying to create a class that has methods called using the PHP __call()magic method. Then this magic method will initialize another object as follows:
public function __call($function, $arguments) {
if ( ! preg_match('/^add/', $function) ) {
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $function, E_USER_ERROR);
}
$class = 'NamodgField_' . substr($function, 3);
call_user_func_array( array(new $class, '__construct'), $arguments);
}
The last line of this code is completely erased! I'm just trying to figure out what I want to do.
I want to be able to pass $argumentsone after another when initializing a new object so that each child class can determine the necessary arguments.
I solved the solution with help eval(), but I really don't like it.
Any ideas?
source
share