php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22047 PHP pollutes the namespace w/ (what looks like) its grammar tokens
Submitted: 2003-02-04 10:02 UTC Modified: 2003-02-04 12:31 UTC
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: szepe at pinerecords dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 4.3.0 OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: szepe at pinerecords dot com
New email:
PHP Version: OS:

 

 [2003-02-04 10:02 UTC] szepe at pinerecords dot com
Since 4.3.0, PHP defines constants that are suspiciously
similar to its grammar tokens.  These cannot be redefined
and should clearly be considered namespace pollution.

For instance, the following example:

<?
  echo T_LIST, ", ", T_STRING, "\n";
?>

will output '345, 304'.
Needless to say, this broke one of my PHP creations
horribly. :)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-04 10:05 UTC] derick@php.net
The tokenizer extension needs those, and changing it now would be breaking all scripts that make use of it. So there is little we can do here...

Derick
 [2003-02-04 10:09 UTC] szepe at pinerecords dot com
Hmm.  I'm convinced PHP should at least file a big fat
warning upon any attempted redefinition of a reserved
constant name, instead of ignoring the instruction
entirely.

Identifiers such as T_LIST are very often used in enums.
 [2003-02-04 10:13 UTC] derick@php.net
That is a good idea, thought it did that. Assigned.
 [2003-02-04 10:20 UTC] szepe at pinerecords dot com
Good, thanks.

Let me clarify -

PHP does log a NOTICE such as

[04-Feb-2003 17:18:22] PHP Notice:
  Constant T_LIST already defined
  in x.php on line 3

but this definitely needs to be a WARNING
or even an ERROR.

-Tomas
 [2003-02-04 10:27 UTC] derick@php.net
A notice is fine, we're not going to change this as it might break scripts out there.
 [2003-02-04 11:48 UTC] szepe at pinerecords dot com
A NOTICE definitely is NOT sufficient.

Remember many setups running older PHP software set
"error_reporting = E_ALL & ~E_NOTICE", because the
amount of notices on undefined array indices and
undefined variables can be quite overwhelming --
and it is precisely these setups that are likely
to be bitten by this problem.

Redefinition of a constant should be a WARNING,
I must insist.
 [2003-02-04 12:31 UTC] sniper@php.net
It's fine as it is -> wont fix.
 [2003-02-04 12:46 UTC] szepe at pinerecords dot com
Guys, if this is how you deal with backwards
compatibility issues, then I'm scared.

I've been maintaining a big PHP project that's about
1MB of very clean code and I need to keep it alive.
This particular bug gave me quite a bit of a headache.
I've provided valid arguments on why a (trivial) change
should be made, and you seem to not really care.  That's
not giving me nice prospects into the future, is it?

Come on, we're talking about constants here!
If a constant is redefined by a program, then
that program is broken by definition and needs
to be told on an appropriate level.
 [2003-02-05 00:49 UTC] szepe at pinerecords dot com
How's changing a NOTICE into a WARNING going to break
anything, anyway?

diff -ur a/Zend/zend_constants.c b/Zend/zend_constants.c
--- a/Zend/zend_constants.c     2002-10-09 16:17:53.000000000 +0200
+++ b/Zend/zend_constants.c     2003-02-05 07:46:35.000000000 +0100
@@ -265,7 +265,7 @@
                if (!(c->flags & CONST_PERSISTENT)) {
                        zval_dtor(&c->value);
                }
-               zend_error(E_NOTICE,"Constant %s already defined", lowercase_name);
+               zend_error(E_WARNING, "Constant %s already defined", lowercase_name);
                ret = FAILURE;
        }
        free_alloca(lowercase_name);
 [2003-02-05 01:00 UTC] chrala at sajt dot cz
> A notice is fine,

redefinition of a constant being only a NOTICE?  
you can't be serious!
 [2003-02-05 05:00 UTC] john at grabjohn dot com
In order to avoid breaking backward compatibility with existing scripts, would it not be possible to allow pre-defined constants to be hidden when a constant is defined in a script with the same name?  As long as a script doesn't need to use both the pre-defined constants, and the new ones, (which a script designed for an old PHP version should not need to do anyway), I can't think of any reason why that wouldn't be an almost perfect solution - problems would only occur if a script assumed that a constant which was not pre-defined, but not defined in the script, evaluated to it's own name.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC