Notice: Undefined index: HTTP_REFERER in /media/raid/Web/www/extra/test_constants.php on line 21
the use of constants in PHP Discussion about the use of constants in PHP, ref. http://fr2.php.net/manual/en/function.constant.php

if 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 Vincent Graux (VGR) - Edaìn Works Ltd - European Experts Exchange  back to list of test scripts


Last update 2023-12-20 11:50:26