PHP相当于send和getattr? [英] PHP equivalent of send and getattr?

查看:87
本文介绍了PHP相当于send和getattr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Ruby受邀参加聚会并带来:

If Ruby gets invited to a party and brings:

foobarobject.send('foomethod') 

..和Python被邀请参加同一个聚会并带来:

.. and Python gets invited to the same party and brings:

getattr(foobarobject, 'foomethod')()

.. PHP必须带来什么?

.. what does PHP have to bring to the party?

奖励问题:如果Ruby和Python嫉妒PHP的聚会偏爱,那么他们会在PHP的文档中搜索哪些英语术语,以便在PHP的背后进行讨论?

Bonus question: If Ruby and Python got jealous of PHP's party-favors, what English terms would they search for in PHP's documentation in order to talk about it behind PHP's back?

推荐答案

PHP带来了这一点:

PHP brings this:

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

...还有焦炭和薯条.

... and the coke and chips.

编辑:

尽管以上术语是 variable variables ,但没有专门讨论的话题对手册中的对象进行操作.但是,您可以使用 call_user_func

Although the term for the above is variable variables there is nothing specifically talking about doing it to an object in the manual. However, you can achieve the same thing with call_user_func:

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

这篇关于PHP相当于send和getattr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆