Discussion about the use of constants in PHP, ref. http://fr2.php.net/manual/en/function.constant.phpif constant TRACE is not set
basic code ("if(TRACE)")
Warning: Use of undefined constant TRACE - assumed 'TRACE' (this will throw an Error in a future version of PHP) in /media/raid/Web/www/extra/test_constants.php on line 38
trace is true <--- ERROR
anonymous' suggestion ("if (TRACE===true)")
Warning: Use of undefined constant TRACE - assumed 'TRACE' (this will throw an Error in a future version of PHP) in /media/raid/Web/www/extra/test_constants.php on line 40
trace is false <--- ERROR
VGR's suggestion
trace is either False , set and not Boolean or unset
if constant TRACE is set to False (Boolean)
basic code ("if(TRACE)")
trace is false
anonymous' suggestion
trace is false
VGR's suggestion
trace is either False , set and not Boolean or unset
if constant TRACE is set to 1 (integer)
basic code ("if(TRACE)")
trace is true <--- WRONG
anonymous' suggestion
trace is false
VGR's suggestion
trace is either False , set and not Boolean or unset
if constant TRACE is set to True (boolean)
basic code ("if(TRACE)")
trace is true
anonymous' suggestion
trace is true
VGR's suggestion
trace is Boolean and true
code used :
basic code :
if (TRACE) echo "trace is true<br>"; else echo "trace is false<br>";
anonymous' suggestion
if (TRACE === true) echo "trace is true<br>"; else echo "trace is false<br>";
VGR's suggestion :
function IsBooleanConstantAndTrue($constname) { // : Boolean
$res=FALSE;
if (defined($constname)) $res=(constant($constname)===TRUE);
return($res);
}
if (IsBooleanConstantAndTrue('TRACE')) echo "trace is Boolean and true<br>"; else echo "trace is either False , set and not Boolean or unset<br>";
@2007 - Edaìn Works Ltd - European Experts Exchange back to list of test scripts
Last update 2024-05-13 15:34:33
Copyright(©)(c) the respective authors. Licensed under the Creative Commons Attribution Share Alike 3.0 License .
These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!