Dot in a PHP Class Name

2019-07-19 05:08发布

问题:

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.



标签: php oop syntax