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 32
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 34
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>";
Access stats :
Thu 15/03/2007 : 8
Fri 16/03/2007 : 4
Sat 17/03/2007 : 4
Sun 18/03/2007 : 3
Mon 19/03/2007 : 3 (google only)
Tue 20/03/2007 : 3 (google only)
Wed 21/03/2007 : 6
Thu 22/03/2007 : 6
Fri 23/03/2007 : 5
Sat 24/03/2007 : 5
Sun 25/03/2007 : 0
Mon 26/03/2007 : 1
Tue 27/03/2007 : 3
Wed 28/03/2007 : 4
Thu 29/03/2007 : 3
Fri 30/03/2007 : 2 (google only)
Sat 31/03/2007 : 3 (google only)
Sun 01/04/2007 : 2 (google only)
Mon 02/04/2003 : 5
Tue 03/04/2007 : 3 (google only)
will discontinue this script soon
@2007 VGR - Edaìn Works Ltd - European Experts Exchange
Last update 2007-04-04 06:42:17
| Add This Article To: |
Del.icio.us |
Digg |
Google |
Spurl |
Blink |
Furl |
Simpy |
Y! MyWeb |