I'm working on a project and I want to try and 'lazy-load' objects.
I've setup a simple class using the Magic Method __call($name, $arguments).
What I'm trying to do is pass the $arguments through, not as an array, but as a list of variables:
public function __call($name, $arguments)
{
// Include the required file, it should probably include some error
// checking
require_once(PLUGIN_PATH . '/helpers/' . $name . '.php');
// Construct the class name
$class = '\helpers\\' . $name;
$this->$name = call_user_func($class.'::factory', $arguments);
}
However, in the method actually being called by the above, $arguments is being passed through as an array and NOT the single variables, E.G.
public function __construct($one, $two = null)
{
var_dump($one);
var_dump($two);
}
static public function factory($one, $two = null)
{
return new self($one, $two);
}
Returns:
array
0 => string '1' (length=1)
1 => string '2' (length=1)
null
Does this make sense, does anyone know how to achieve what I'm trying to?