Edit report at https://bugs.php.net/bug.php?id=64637&edit=1
ID: 64637
Comment by: phpmpan at mpan dot pl
Reported by: rstoll at tutteli dot ch
Summary: redefine NULL
Status: Feedback
Type: Bug
Package: *Languages/Translation
Operating System: windows
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
I've just noticed somene's code on 3v4l: a lowercase versions may be redefined
too if they're used in namespace.
---------------------------------
namespace ns;
define('ns\\true', 'blarg1');
define('ns\\false', 'blarg2');
define('ns\\null', 'blarg3');
var_dump(true, false, null);
---------------------------------
This also works in PHP run from Apache and `php -f` (tested in 5.4.14 on
Arch64).
To make things funnier:
---------------------------------
define('int', 123);
var_dump(int + int);
---------------------------------
Previous Comments:
------------------------------------------------------------------------
[2013-04-19 17:12:25] rstoll at tutteli dot ch
Some more information about the define statement. I can also use define for
things like that:
define("1",0);
define("if","else");
It doesn't have any influence on the code, if one writes 1 or if after the
define then 1 is still an int and if still the keyword if, but it should not be
possible in my opinion.
------------------------------------------------------------------------
[2013-04-19 16:10:14] phpmpan at mpan dot pl
The same issue applies to TRUE and FALSE.
Example:
define('TRUE', FALSE);
define('FALSE', TRUE);
var_dump(TRUE);
var_dump(FALSE);
------------------------------------------------------------------------
[2013-04-15 20:13:09] phpmpan at mpan dot pl
For some reason my earlier comment was not published here.
It contained a table of test results from 7 different PHP versions and 3
testing modes. I'll have no time to rebuild the table now, but the point is
that I confirmed the bug on Linux for various PHP versions (including trunk
snapshot). However, the bug appeared only in __interactive__ CLI mode, not in
`php -f` or PHP run from Apache. It seems that any NULL spelling is affected,
except all-lowercase version. Also redefinition of particular spelling doesn't
affect other spellings, so one can define NuLl as 'x', nULL as 'y' and each of
them will keep their defined value.
I would also point out that a link provided by Laruence in the first comment
outputs "hello world" for some versions.
------------------------------------------------------------------------
[2013-04-15 09:07:11] rstoll at tutteli dot ch
I still got the "hello world" even without any extension. The output is
slightly different, I got NULL instead of null without xdebug. But still
NULL
NULL
NULL
string(11) "hello world"
Notice: Constant null already defined
for PHP 5.3.5 and PHP 5.4.7
In my opinion this bug can be closed because probably no one will ever do this.
As side mark, also http://3v4l.org/8knru does not show a notice for the first
define. Thus the implementation is not entirely correct. I assume your PHP
version behaves differently than mine in terms of symbol resolution. In my PHP
version the case matters. So if I write NULL a different symbol is resolved
than when I write null. In your version always null is resolved. That could be
the reason why you do not get "hello world" as output. But I do not really know
the internals of PHP, it's just an assumption.
------------------------------------------------------------------------
[2013-04-15 03:04:09] [email protected]
please try again with a pure PHP (without any extension which will alter PHP
behavior, like xdebug, xhprof, apc/opcache, or taint)
thanks
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=64637
--
Edit this bug report at https://bugs.php.net/bug.php?id=64637&edit=1