Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a namespace start with a number in PHP?

Tags:

namespaces

php

When declaring the following namespace:

<?php

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?

like image 856
hielsnoppe Avatar asked Nov 23 '15 16:11

hielsnoppe


1 Answers

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:

<?php

namespace Example\V_3000;
like image 107
hielsnoppe Avatar answered Sep 25 '22 07:09

hielsnoppe