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

 

 [2005-06-01 02:26 UTC] aneroid at gmail dot com
Description:
------------
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');
     print_r(get_defined_constants());
}

// 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)

Patches

Pull Requests

History

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] johannes@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

see also 
http://www.zend.com/zend/week/week218.php#Heading3 
 [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 http://www.zend.com/zend/week/week218.php#Heading3).

nothing in the manual about constants (http://www.php.net/manual/en/language.constants.php) or define() (http://www.php.net/manual/en/function.define.php) documents this behaviour.

anyways. thanks for clarifying things.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC