7

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?

2 Answers 2

19

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;
2
  • Mate, I would have just said "No".
    – Flosculus
    Commented Nov 23, 2015 at 16:08
  • Did You.. answered just after asking?
    – instead
    Commented Dec 6, 2017 at 17:55
1

Note: Special character cannot be used. The only special character I have found that works is the underscore (_). For example if you want a folder for version 3.0.01, then do the following:

    <?php
    namespace Example\v3_0_01;
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.