|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-10-15 15:29 UTC] kenashkov at gmail dot com
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 04:00:02 2025 UTC |
<? namespace NS1::ns2; const const2 = 'value2'; define('NS1::ns2::const1','value'); $dc = get_defined_constants(true); print '<pre>'.print_r($dc['user'],true).'</pre>'; ?> gives Array ( [ns1::ns2::const2] => value2 [NS1::ns2::const1] => value )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?