Notice: Undefined index: HTTP_REFERER in W:\www\extra\test_constants.php on line 20
the use of constants in PHP
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)")
Notice: Use of undefined constant TRACE - assumed 'TRACE' in W:\www\extra\test_constants.php on line 37
trace is true <--- ERROR
anonymous' suggestion ("if (TRACE===true)")
Notice: Use of undefined constant TRACE - assumed 'TRACE' in W:\www\extra\test_constants.php on line 39
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 2009-10-30 09:04:56
| Add This Article To: |
Del.icio.us |
Digg |
Google |
Spurl |
Blink |
Furl |
Simpy |
Y! MyWeb |