Reply
Comparing to NULL
Old 05-03-2007, 05:49 PM Comparing to NULL
NullPointer's Avatar
Will Code for Food

Posts: 502
Name: Matt
Location: Irvine, CA
Quick question. Different langauges act in different ways when you compare something to NULL.

What would happen in PHP if I were to compare something to null?
would 1 >= NULL return true?
would NULL >= 1 return false?
__________________
http://tinsology.com/ - Under construction
NullPointer is online now
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-03-2007, 06:24 PM Re: Comparing to NULL
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
Don't use this syntax when it comes to null.

use the typed comparison operators:
http://www.php.net/manual/en/languag...comparison.php
Either === or !== , which will check the type of the variable and it's php logical value after casting.
You can use is_null() too to test a value.

Appart this, in your question, both statement will be correct.
As null cast to 0:
1 is >= to null
null is not >= to 1
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 05-03-2007, 06:28 PM Re: Comparing to NULL
NullPointer's Avatar
Will Code for Food

Posts: 502
Name: Matt
Location: Irvine, CA
Thanks a lot. I've had problems in other languages like java when things poped up as Null when they weren't supposed to (hence my name).
__________________
http://tinsology.com/ - Under construction
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 05-03-2007, 09:54 PM Re: Comparing to NULL
Super Talker

Posts: 123
Name: Nick Mallare
In Java, it's simply:

Code:
if( <variablename> == NULL )
Right?

Nick
nmallare is offline
Reply With Quote
View Public Profile Visit nmallare's homepage!
 
Reply     « Reply to Comparing to NULL
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13957 seconds with 12 queries