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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

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

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post 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++
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

I use

Code: Select all

if( $val == NULL )
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post by detrox »

I got it, Thanks very much.
Post Reply