php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54105 namespace names starting with \ should be invalid
Submitted: 2011-02-26 13:45 UTC Modified: 2011-02-26 14:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: theseer@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.5 OS: irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: theseer@php.net
New email:
PHP Version: OS:

 

 [2011-02-26 13:45 UTC] theseer@php.net
Description:
------------
Defining a namespace who's name starts with a \ is interpreted as a constant though resolving a constant for the namespace name is not supported (and should not! :) ) and results in an empty string being used.


Test script:
---------------
test.php:

<?php
 define('a','\foo');
 require 'a.php';


a.php:

<?php
namespace \a; 
var_dump(__NAMESPACE__);
class b { }

Expected result:
----------------
(Parse?) Error due to invalid namespace definition

Actual result:
--------------
Empty string for __NAMESPACE__ or undefined constant a depending wheter or not the file "a.php" got required or called directly

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-26 14:00 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-02-26 14:00 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

define() does no checking of the name.

http://devzone.zend.com/article/475#Heading3
 [2011-02-26 14:13 UTC] johannes@php.net
-Status: Bogus +Status: Open
 [2011-02-26 14:13 UTC] johannes@php.net
Reading is hard ... seems valid
 [2011-02-26 14:20 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-02-26 14:20 UTC] felipe@php.net
'namespace \a;' is not declaring a namespace, but fetching a constant 'a' from the current namespace. (namespace\a)

http://docs.php.net/manual/en/language.namespaces.nsconstants.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 20:01:32 2025 UTC