note 112293 added to language.types.null
| From: | Toycat | Date: | Wed, 29 May 2013 09:11:12 +0000 |
| Subject: | note 112293 added to language.types.null | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194980@lists.php.net to get a copy of this message | ||
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:
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
);
}
----
Server IP: 69.147.83.199
Probable Submitter: 90.177.101.182
----
Manual Page -- http://php.net/manual/en/language.types.null.php
Edit -- https://master.php.net/note/edit/112293
Del: integrated -- https://master.php.net/note/delete/112293/integrated
Del: useless -- https://master.php.net/note/delete/112293/useless
Del: bad code -- https://master.php.net/note/delete/112293/bad+code
Del: spam -- https://master.php.net/note/delete/112293/spam
Del: non-english -- https://master.php.net/note/delete/112293/non-english
Del: in docs -- https://master.php.net/note/delete/112293/in+docs
Del: other reasons-- https://master.php.net/note/delete/112293
Reject -- https://master.php.net/note/reject/112293
Search -- https://master.php.net/manage/user-notes.php