PHP equivalent of send and getattr?

If Ruby is invited to a party and brings:

foobarobject.send('foomethod') 

.. and Python is invited to the same side and brings:

getattr(foobarobject, 'foomethod')()

.. What should PHP do for a party?

Bonus question: If Ruby and Python are jealous of third-party PHP partners, what English terms will they look for in the PHP documentation to talk about this back for PHP?

+5
source share
2 answers

PHP brings the following:

$foobarobject->{"foomethod"}();

... and coke and chips.

EDIT

Although the term is for the above variable variables, there is nothing concrete about talking about how to do this with the object in the manual. However, you can achieve the same call_user_func::

call_user_func(array($foobarobject, "foomethod"));
+10

. , , , , , .

$method = "foomethod";
$foobarobject->$method();

.

$method = new ReflectionMethod('Foobar', 'foomethod');
$method->invoke(null);
+3

All Articles