Wednesday, September 19, 2018

Can a namespace start with a number in PHP?



When declaring the following namespace:





namespace Example\3000;


I got this error:



Parse error:  syntax error, unexpected '3000' (T_LNUMBER), expecting identifier (T_STRING) in [...]



So I wondered whether a namespace in PHP may start with a number?


Answer



No, it must not. It must start with a letter.



It took me a while to find this in a comment on PHP.net.



To use numbers e.g. for versioning it is necessary to prepend letters, e.g. like in the following:





namespace Example\V_3000;

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...