Looks like impossible do something like that:
class Service
{
public function get($argument1, $argument2)
{
echo "Arguments: $argument1, $argument2.";
}
}
class Main
{
public function __callStatic($method, $arguments)
{
$method = "get".ucfirst($method);
$arguments = implode(", ", $arguments);
$object = self::$method;
return $object->get($arguments);
}
public static function getService()
{
return new Service;
}
}
$main = new Main;
$main::Service("1", "2"); // Should output 'Arguments: 1, 2.'
The problem is the self mess everthing, with this will be possible.
Use self::$variable, self this we have a variable in the Main context.
$object = self don't work too.
$object = clone self dont' work too.
define("method", $method);
self::method will not work because self thinks is a class constant property.
this can't be used.
Is there a way to perform this?