php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64637 redefine NULL
Submitted: 2013-04-11 23:23 UTC Modified: 2013-10-15 11:54 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rstoll at tutteli dot ch Assigned:
Status: No Feedback Package: *Languages/Translation
PHP Version: 5.4.7 OS: windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
47 + 33 = ?
Subscribe to this entry?

 
 [2013-04-11 23:23 UTC] rstoll at tutteli dot ch
Description:
------------
It is possible to redefine NULL (however, not null). No one probably does that but it should not be possible. Maybe there are more of this kind of errors. 

Test script:
---------------
	var_dump(null); // null
	var_dump(NULL); // null
	define("NULL","hello world");
	var_dump(null); // null
	var_dump(NULL); // hello world
	define("null","hello world"); //Notice: Constant null already defined



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-12 04:14 UTC] laruence@php.net
http://3v4l.org/8knru

I didn't see a "hello world" outputted
 [2013-04-12 04:14 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-04-12 11:21 UTC] rstoll at tutteli dot ch
-Status: Feedback +Status: Open -Operating System: +Operating System: windows -PHP Version: 5.4.14 +PHP Version: 5.4.7
 [2013-04-12 11:21 UTC] rstoll at tutteli dot ch
Maybe the bug only exists on windows.
I got the error for 5.4.7 and 5.3.5
 [2013-04-12 16:57 UTC] anon at anon dot anon
Tested on PHP 5.3.5 on Windows and I just get NULL as output all four times, and then the notice. Seems normal.
 [2013-04-12 18:32 UTC] rstoll at tutteli dot ch
strange that you do not have the same problem. However, a notice should already be shown for the first usage of define.
 [2013-04-15 03:04 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-04-15 03:04 UTC] laruence@php.net
please try again with a pure PHP (without any extension which will alter PHP 
behavior, like xdebug, xhprof, apc/opcache, or taint)

thanks
 [2013-04-15 09:07 UTC] 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 20:13 UTC] 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-19 16:10 UTC] 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-19 17:12 UTC] 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 17:34 UTC] phpmpan at mpan dot pl
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);
---------------------------------
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 18:01:25 2020 UTC