php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50038 PHP doesn't like it when a namespace starts with a number for example 12eggs
Submitted: 2009-10-30 10:35 UTC Modified: 2009-10-30 16:03 UTC
From: me at gerryevans dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.0 OS: CentOS
Private report: No CVE-ID: None
 [2009-10-30 10:35 UTC] me at gerryevans dot com
Description:
------------
PHP doesn't like it when a namespace starts with a number for example a 
namespace 12eggs will get a parse error ("syntax error, unexpected 
T_LNUMBER, expecting T_STRING or T_NS_SEPARATOR or '{'").

Reproduce code:
---------------
<?php
  
  namespace 12eggs;
  
  echo __NAMESPACE__;
  
?>

Expected result:
----------------
12eggs

Actual result:
--------------
Parse error:  syntax error, unexpected T_LNUMBER, expecting T_STRING or 
T_NS_SEPARATOR or '{' in FILE on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-30 10:49 UTC] me at gerryevans dot com
I have tested this error on a CentOS server running Apache 2 + PHP 5.3 and Lighttpd + PHP 5.3.

The php.ini both times was a php.ini-production with the only change "expose_php" to Off.
 [2009-10-30 12:08 UTC] colder@php.net
namespaces' names follow the same rule as classes/functions' names, which can't start by numbers either.
 [2009-10-30 12:39 UTC] me at gerryevans dot com
Yep, that make sense.

You should include in the PHP docs that the naming rules apply to 
namespaces, as at the moment their no mention of it.

Out of interest, is there any reason why the naming rules doesn't allow 
the names to start with numbers?
 [2009-10-30 16:03 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Identifiers have to start with a letter. The same rule applies for class names, function names, variables, constants, ...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 14:00:01 2025 UTC