note 85609 added to function.constant
| From: | corydotmawhorter at ephectivedotcom | Date: | Mon, 08 Sep 2008 21:08:48 +0000 |
| Subject: | note 85609 added to function.constant | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144246@lists.php.net to get a copy of this message | ||
This is how I check to see if a bool constant is true:
<?php
function consttrue($const) {
return !defined($const) ? false : constant($const);
}
?>
Examples
<?php
var_dump(consttrue('UNDEFINED_CONST'));
define('SOME_CONST', true);
var_dump(consttrue('SOME_CONST'));
define('SOME_CONST2', false);
var_dump(consttrue('SOME_CONST2'));
?>
Returns
bool(false)
bool(true)
bool(false)
If it isn't defined it will return false, otherwise it will return the value of the constant...
which would be either true/false depending on what you set it to.
----
Server IP: 209.41.74.194
Probable Submitter: 98.209.42.6
----
Manual Page -- http://www.php.net/manual/en/function.constant.php
Edit -- https://master.php.net/note/edit/85609
Del: integrated -- https://master.php.net/note/delete/85609/integrated
Del: useless -- https://master.php.net/note/delete/85609/useless
Del: bad code -- https://master.php.net/note/delete/85609/bad+code
Del: spam -- https://master.php.net/note/delete/85609/spam
Del: non-english -- https://master.php.net/note/delete/85609/non-english
Del: in docs -- https://master.php.net/note/delete/85609/in+docs
Del: other reasons-- https://master.php.net/note/delete/85609
Reject -- https://master.php.net/note/reject/85609
Search -- https://master.php.net/manage/user-notes.php