Description:
------------
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:
ns1::ns2::const1;
But if the constant was defined using define(), it is kept with the capitalization:
<?
define('NS1::ns2::const1','value');
?>
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:
---------------
<?
define('NS1::ns2::const1','value');
print NS1::ns2::const1;//error
//print ns1::ns2::const1;//would give error too
?>
Expected result:
----------------
value
Actual result:
--------------
Fatal error: Class 'NS1::ns2' not found in /home/local/tests/t35.php on line 3

Patches

Pull Requests

History

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.

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?

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.

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
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Thanks for reporting it.