|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33208 define() allows non variable-like strings (spaces, slashes)
Submitted: 2005-06-01 02:26 UTC Modified: 2005-06-01 16:05 UTC
From: aneroid at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 5.0.3 OS: linux & windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: aneroid at gmail dot com
New email:
PHP Version: OS:


 [2005-06-01 02:26 UTC] aneroid at gmail dot com
define()ing a constant with spaces, / signs, etc. doesn't throw an error (or warning).

i happened to try to create a constant with the name
'U/L DIR' and it worked. that's two illegal chars. since constant names like "2FOO" are checked and not allowed, shouldn't these also not be allowed?

sure doesn't satisfy "The name of a constant follows the same rules as any label in PHP." or the regexp [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

a name like that obviously can't be used (tried quotes and braces) but it works just fine with 'defined()', 'constant()' and shows up in get_defined_constants().

Reproduce code:
define('U/L DIR', 'myuploaddir');

if (defined('U/L DIR')) {  //true
     echo 'yup';
     echo constant('U/L DIR');

// all the lines above print 'myuploaddir' for 'U/L DIR'

Expected result:
E_ERROR since it's violates label rules (an E_WARNING at the least?)

Actual result:
spaces, etc. work just fine. (it shouldn't)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-01 03:07 UTC] aneroid at gmail dot com
btw, it may imply corresponding bugs in 'constant()' and 'defined()'.

imho, they would be better left untouched so it's easier to use them as they currently work. if they are fixed, they should produce E_WARNING/NOTICEs (worst case) so they can be suppressed with '@' when checking. this is especially true of constant().

(i'd entered this as a comment but it wasn't displaying)
 [2005-06-01 15:16 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

see also 
 [2005-06-01 16:05 UTC] aneroid at gmail dot com
i hardly think it's "not a bug". but i DO agree with the reasons for leaving the behaviour as is, particularly: to not break existing code and speed (as mentioned in

nothing in the manual about constants ( or define() ( documents this behaviour.

anyways. thanks for clarifying things.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 11:01:32 2024 UTC