You are here: Re: Help needed with is_null « PHP Programming Language « IT news, forums, messages
Re: Help needed with is_null

Posted by Jerry Stuckle on 08/04/07 12:46

Matt Madrid wrote:
> Jerry Stuckle wrote:
>> Big Moxy wrote:
>>> Would someone be so kind as to tell me what is wrong with this code?
>>>
>>> (1) This code block indicates the session variable nomex is null.
>>> if (is_null($_SESSION['nomex'])){
>>> echo " is null.";
>>> }
>>> else {
>>> echo " is not null.";
>>> }
>>>
>>> (2) However on the same page this code block always adds 100 to the
>>> price.
>>> if ($_SESSION['nomex'] != "^^no^^"){
>>
>> If it wasn't defined before, it is now.
>
> Maybe, but if referencing an undefined variable sets it, it will be set
> to NULL.
>
> if ($_SESSION['nothing']){}
> var_dump($_SESSION['nothing']);
>
> output: NULL
>
>>
>>> if (!is_null($_SESSION['nomex'])){
>>
>> So this will never be true.
>
> What do you mean it will never be true. It will be true if that variable
> had a non-null value to begin with.

You're correct - it will be true in this case.
>
>>
>> BTW - if you're checking to see if something is set, isset() is
>> better. But either way, check BEFORE you reference it.
>>
>
> Either way in this case.

Not at all. There is a definite difference between isset() and isnull().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this 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

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