note 112293 deleted from language.types.null by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:55:48 +0000 |
| Subject: | note 112293 deleted from language.types.null by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210839@lists.php.net to get a copy of this message | ||
Note Submitter: Toycat
----
Be careful using NULL together with namespaces. If a NULL constant is redefined in a namespace other
than global, you will get unexpected results when comparing to NULL inside the namespace. Instead
always use \NULL, \FALSE, and \TRUE when comparing. Otherwise it may lead to application failures
and potential security issues where certain checks could be effectively disabled.
A simple example to demonstrate the behavior:
<?php
namespace RedefinedConstants {
// redefining global namespace constants has no effect
define('NULL', 'I am not global NULL!');
define('TRUE', 'I am not global TRUE!');
define('FALSE', 'I am not global FALSE!');
// redefining local namespace constants will work
define('RedefinedConstants\NULL', 'I am not NULL!', \TRUE);
define('RedefinedConstants\FALSE', 'I am not FALSE!', \TRUE);
define('RedefinedConstants\TRUE', 'I am not TRUE!', \TRUE);
var_dump(
NULL, \NULL, null, \null, Null, \Null,
FALSE, \FALSE, false, \false, False, \False,
TRUE, \TRUE, true, \true, True, \True
);
}
?>