How to chain call functions by using a string containing that chain in PHP
问题 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