|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46304 Defining namespaced constant using define() defines CASE SENSITIVE namespace
Submitted: 2008-10-15 15:29 UTC Modified: 2009-01-12 21:55 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kenashkov at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-11-11 OS: *
Private report: No CVE-ID: None
 [2008-10-15 15:29 UTC] kenashkov at gmail dot com
The current implementatino of namespaces is case INSENSITIVE. But defining a constant using define and having capitals in the namespace makes the defined constant unreachable.

We can verify this using get_defined_constants(). In case a constant was defined like:
namespace NS1::ns2;
const const1;
we can see the the defined constant/namespace is in fact:
But if the constant was defined using define(), it is kept with the capitalization:
get_defined_constants() gives NS1::ns2::const1.

But because the namespaces are case insensitive the call:
print NS1::ns2::const1;
resolves in fact to ns1::ns2::const1 which is undefined.

Reproduce code:
print NS1::ns2::const1;//error
//print ns1::ns2::const1;//would give error too

Expected result:

Actual result:
Fatal error: Class 'NS1::ns2' not found in /home/local/tests/t35.php on line 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-15 15:33 UTC] kenashkov at gmail dot com
I had a quick look again over the docs and nowhere is documented that the namespaces are case insensitive. I think this should go in the docs, as well if this issue with define() wont be fixed, to be documented too.
 [2008-10-15 15:39 UTC] kenashkov at gmail dot com
namespace NS1::ns2;
const const2 = 'value2';
$dc = get_defined_constants(true);
print '<pre>'.print_r($dc['user'],true).'</pre>';

    [ns1::ns2::const2] => value2
    [NS1::ns2::const1] => value
 [2008-10-15 15:57 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The define() works in runtime.
 [2008-10-15 16:08 UTC] kenashkov at gmail dot com
I know it is during runtime, but instead of marking it as bogus, would be better to document it.
I'm changing the category.
This behaviour has to be documented, or fixed. Is it possible to remap to lowercase internally the result of the define('CaSe::Sensitive::const')? Or is undesirable from consistant POV?
 [2008-10-16 04:04 UTC]
I think this is a valid bug - we store classes with lower-cased name, but store the original CaSeD name in the class.  runtime define() should perform the same steps that compile-time define() does to ensure the namespaced constant is accessible in the same way.  It's a bit slower, but more accurate.  I'd say move this back to scripting engine, but I'll leave it up to felipe.
 [2008-10-16 11:12 UTC]
Oh, sorry. I misread your report. Thanks Greg.
 [2008-11-11 10:37 UTC]
This better be fixed before PHP 5.3.0 goes out - hence critical..
 [2009-01-12 21:55 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Thanks for reporting it.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 14:01:32 2024 UTC