Reply to Re: Zero and NULL

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация