I have a chain call like so:
$object->getUser()->getName();
I know that I can use a string to call a function on an object:
$functionName = 'getUser';
$object->$functionName() or call_user_func(array($object, functionName))
I was wondering if it was possible to do the same for a chain call? I tried to do:
$functionName = 'getUser()->getName';
$object->functionName();
But I get an error
Method name must be a string
I guess this is because the () and -> cannot be interpreted since they are part of a string? Is there any way I can achieve this without having to do:
$function1 = getUser;
$function2 = getName;
$object->$function1()->$function2();
The aim is to get an array of functions and to chain them, in order to call this chain on the given object, e.g.:
$functions = array('getCoordinates', 'getLongitude'); // or any other chain call
$functionNames = implode('()->',$functions);
$object->$functionNames()
return $this;'.'getUser()->getName'? It'd be pretty darn trivial if you "support" a more neutral format likegetUser.getName. Would you need to support parameters as well? (If that's the case I'd question whether this whole endeavour is a good idea though.)