note 106311 added to function.define

From: Date: Wed, 26 Oct 2011 22:35:58 +0000
Subject: note 106311 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-184155@lists.php.net to get a copy of this message
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? ---- Server IP: 192.41.42.26 Probable Submitter: 76.18.87.226 ---- Manual Page -- http://www.php.net/manual/en/function.define.php Edit -- https://master.php.net/note/edit/106311 Del: integrated -- https://master.php.net/note/delete/106311/integrated Del: useless -- https://master.php.net/note/delete/106311/useless Del: bad code -- https://master.php.net/note/delete/106311/bad+code Del: spam -- https://master.php.net/note/delete/106311/spam Del: non-english -- https://master.php.net/note/delete/106311/non-english Del: in docs -- https://master.php.net/note/delete/106311/in+docs Del: other reasons-- https://master.php.net/note/delete/106311 Reject -- https://master.php.net/note/reject/106311 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184155) next »