Reply to Re: Zero and NULL

Your name:

Reply:


Posted by J.O. Aho on 01/09/07 13:07

Paul Lautman wrote:
> I have the following switch statement:
>
> switch ($record->sub_page) {
> case -1:
> $this->page = 6;
> $error_message = '<center>You appear to have already completed the
> form.</center>';
> break;
> case 0:
> $this->page = 5;
> ff_query("UPDATE #__gateway_form_1 SET `sub_page`=-1 WHERE
> userid=$my->id and `expiry_date` = '$expiry_date'");
> break;
> default:
> do something else
> }
>
> The value of $record->sub_page can be NULL. If it is NULL, the case for 0
> seems to fire. I really need the default action to happen when
> $record->sub_page is NULL or a +ve value.
>
> However if I do:
>
> switch ($record->sub_page) {
> case -1:
> $this->page = 6;
> break;
> case NULL:
> do something else;
> break;
> case 0:
> $this->page = 5;
> break;
> default:
> do something else;
> }
>
> then the switch manages to tell the difference between a NULL and a zero.
>
> Is it correct that php treats NULL as 0?
> Can anyone suggest a good fix?

NULL and 0 are many times treated as false, so you do need to take care of
things and check NULL/0/false.

--

//Aho

[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

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