note 106311 deleted from function.define by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:16:34 +0000 |
| Subject: | note 106311 deleted from function.define by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197128@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster@PersonalInformationTechnology.
----
Be careful when testing for defined boolean values.
For example, consider a section of code defining other constants, and one control to see if they
are defined.
file constants.php
<?php
define("FOO", value);
define("BAR", value2);
define("CONST_DEFINED", true);
?>
and, in another file
<?php
if(CONST_DEFINED)
{/* use them */}
?>
This will always return true, regardless if the constants.php file was successfully included (at
least in 5.2.17)
A better approach is to define the negative:
define("CONST_NOT_DEF", false)
and test that negative
if(!CONST_NOT_DEF)....
Checking for defined("CONST_DEFINED") also works, but why have a boolean constant if one
isn't going to use the value directly?