Dot in a PHP Class Name

六眼飞鱼酱① 提交于 2020-01-04 06:11:16

问题


Is it illegal in PHP to have a class named

class foo.bar{


}

I am getting errors that say { expected instead of . is there a configuration work around to this or is the error talking abouts something else?


回答1:


From the manual:

A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Dots are not valid and you can't change any settings to make them valid.




回答2:


Dots are not allowed in class names. Period.




回答3:


PHP class names can't have periods in them. There's no way around this.




回答4:


The dot . is the string-concatenation operator, thus its not allowed anywhere in an identifier.




回答5:


A dot isnt allowed, as documented: http://php.net/manual/en/language.oop5.basic.php




回答6:


Dots are not allowed.

The class name can be any valid label which is a not a PHP reserved word. A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

Shamelesse ripped from here.



来源:https://stackoverflow.com/questions/6123660/dot-in-a-php-class-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!