Dot in a PHP Class Name

2019-07-19 04:42发布

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?

标签: php oop syntax
6条回答
来,给爷笑一个
2楼-- · 2019-07-19 05:24

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-19 05:25

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

查看更多
Animai°情兽
4楼-- · 2019-07-19 05:28

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.

查看更多
太酷不给撩
5楼-- · 2019-07-19 05:36
劳资没心,怎么记你
6楼-- · 2019-07-19 05:42
聊天终结者
7楼-- · 2019-07-19 05:48

Dots are not allowed in class names. Period.

查看更多
登录 后发表回答