是否有可能“逃逸” PHP中的方法名称能够使用与保留关键字冲突的方法名称吗? [英] Is it possible to "escape" a method name in PHP, to be able to have a method name that clashes with a reserved keyword?

查看:113
本文介绍了是否有可能“逃逸” PHP中的方法名称能够使用与保留关键字冲突的方法名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中做MVC,我想在我的Controller里面有一个list()方法,以使URL / entity / list / parent_id显示属于该父类的所有x



但是,我不能有一个名为list()的方法,因为它是一个PHP保留关键字。



在VB.Net中,例如,如果我需要有一个与保留关键字冲突的名称,我可以将其包装在[reserved_name]中。

在SQL中,你可以做同样的事情事情。

在MySQL中,你使用反引号`



PHP中有些语法指定将其视为标识符,而不是关键字?



(注意:我知道我可以使用路由来做到这一点,而没有一个list()方法,我也可以简单地调用动作其他的。是否PHP提供这种转义)

解决方案

使用变量名称可以使用括号:

  $ {'array'} =test; 
echo $ {'array'};

但PHP不提供转义功能名称的方法。



如果你想要一个用户定义的方式来解决这个问题,请查看这个评论:



http://www.php.net/manual/en/reserved。 keywords.php#93368


I'm doing MVC in PHP, and i'd like to have a list() method inside my Controller, to have the URL /entity/list/parent_id, to show all the "x" that belong to that parent.

However, I can't have a method called list(), since it's a PHP reserved keyword.

In VB.Net, for example, if I need to have something with a name that clashes with a reserved keyword, I can wrap it in [reserved_name].
In SQL, you can do the same thing.
In MySQL, you use the backtick `

Is there some syntax in PHP that specifies "treat this as an identifier, not as a keyword"?

(NOTE: I know I can use routes to do this without having a list() method. I can also simply call the action something else. The question is whether PHP provides this kind of escaping)

解决方案

With variable names you can use the bracket signs:

${'array'} = "test";
echo ${'array'};

But PHP does not provide a method for escaping function names.

If you want a 'user-defined' way of getting around this, check out this comment:

http://www.php.net/manual/en/reserved.keywords.php#93368

这篇关于是否有可能“逃逸” PHP中的方法名称能够使用与保留关键字冲突的方法名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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