note 108236 added to language.namespaces.faq
| From: | manolachef at gmail dot com | Date: | Tue, 10 Apr 2012 14:32:32 +0000 |
| Subject: | note 108236 added to language.namespaces.faq | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187046@lists.php.net to get a copy of this message | ||
There is a way to define a namespaced constant that is a special, built-in constant, using define
function and setting the third parameter case_insensitive to false:
<?php
namespace foo;
define(__NAMESPACE__ . '\NULL', 10); // defines the constant NULL in the current namespace
var_dump(NULL); // will show 10
var_dump(null); // will show NULL
?>
No need to specify the namespace in your call to define(), like it happens usually
<?php
namespace foo;
define(INI_ALL, 'bar'); // produces notice - Constant INI_ALL already defined. But:
define(__NAMESPACE__ . '\INI_ALL', 'bar'); // defines the constant INI_ALL in
the current namespace
var_dump(INI_ALL); // will show string(3)"bar". Nothing unespected so far. But:
define('NULL', 10); // defines the constant NULL in the current namespace...
var_dump(NULL); // will show 10
var_dump(null); // will show NULL
?>
If the parameter case_insensitive is set to true
<?php
namespace foo;
define (__NAMESPACE__ . '\NULL', 10, true); // produces notice - Constant null already
defined
?>
----
Server IP: 69.147.83.197
Probable Submitter: 92.84.32.139
----
Manual Page -- http://www.php.net/manual/en/language.namespaces.faq.php
Edit -- https://master.php.net/note/edit/108236
Del: integrated -- https://master.php.net/note/delete/108236/integrated
Del: useless -- https://master.php.net/note/delete/108236/useless
Del: bad code -- https://master.php.net/note/delete/108236/bad+code
Del: spam -- https://master.php.net/note/delete/108236/spam
Del: non-english -- https://master.php.net/note/delete/108236/non-english
Del: in docs -- https://master.php.net/note/delete/108236/in+docs
Del: other reasons-- https://master.php.net/note/delete/108236
Reject -- https://master.php.net/note/reject/108236
Search -- https://master.php.net/manage/user-notes.php