Page 1 of 1

Who can tell me the difference between is_null(), =="&q

Posted: Wed Jun 04, 2003 9:25 am
by detrox
A form has a text area named comment.

Now, I wanna know whether comment is empty.If I use

Code: Select all

if is_null($_GETї"comment"]);
It does not work.
Only

Code: Select all

if ($_GETї"comment"] == "");
can work.

Who can tell me why?

Thanks very much.

Posted: Wed Jun 04, 2003 9:28 am
by twigletmac
If you are testing for a NULL value you can use is_null(), however, if you are testing to see if a variable is empty (as you are) then you should use empty().

Mac

Posted: Wed Jun 04, 2003 11:48 pm
by detrox
So it means that a null variable is a variable whose value is null.A empty variable doesn't contain anything?

That is so different from C/C++

Posted: Thu Jun 05, 2003 12:45 am
by Sevengraff
I use

Code: Select all

if( $val == NULL )

Posted: Thu Jun 05, 2003 2:49 am
by volka
empty() is the opposite of ==TRUE
therefor an empty string like '' is empty as is the number 0 and the values FALSE & NULL.
is_null() only checks for NULL.

Posted: Thu Jun 05, 2003 6:19 am
by detrox
Excuse me, volka.I do not understand about 'empty() is the opposite of ==TRUE'. Is that mean 'If (empty($a))' is the same as 'If $a == FALSE'? That's puzzled.

Posted: Thu Jun 05, 2003 6:22 am
by volka
almost yes
+ empty() does not throw a warning if $a is undefined.

see also:
http://php.net/empty
http://www.php.net/manual/en/language.t ... an.casting

Posted: Thu Jun 05, 2003 6:27 am
by detrox
I got it, Thanks very much.