Posted by Umberto Salsi on 01/09/07 14:00
"Paul Lautman" <paul.lautman@btinternet.com> wrote:
> Is it correct that php treats NULL as 0?
The switch() statement uses the weak comparison operator ==.
When the weak operator == is used the reply is yes: 0==NULL.
> Can anyone suggest a good fix?
1. Avoid to mix different types in expressions: it's confusing and dangerous.
For example, ensure the expression inside the switch() be int: switch( (int)
(EXPR) ){ ... }. Avoid to use a string as selector because "09" == 9 ==
"0x9" ==... difficult to say what ever else can match.
2. Do not use the switch(), use if() instead with the strong comparison
operator === as in this example:
if(EXPR === 1){
}else if(EXPR === NULL){
}else{
}
Best regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it
[Back to original message]
|