php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kenashkov at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

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.
 [2008-10-15 15:39 UTC] kenashkov at gmail dot com
<?
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
)
 [2008-10-15 15:57 UTC] felipe@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

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] cellog@php.net
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] felipe@php.net
Oh, sorry. I misread your report. Thanks Greg.
 [2008-11-11 10:37 UTC] jani@php.net
This better be fixed before PHP 5.3.0 goes out - hence critical..
 [2009-01-12 21:55 UTC] stas@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 02:02:52 2024 UTC