Re: Re: Equivalency of null

From: Date: Tue, 08 Aug 2006 09:33:58 +0000
Subject: Re: Re: Equivalency of null
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24856@lists.php.net to get a copy of this message
On 8/8/06, Markus Ernst <derernst@gmx.ch> wrote:
LFaR schrieb: 1) null == '' 2) null == array() 3) array() != '' Item 3 surprised me. I wrote a little table to make sure I wasn't seeing things. Can anyone add a word of explanation as to why 3) is not false, when 1) and 2) are true? The == operator stands for loose comparison - different types of values are compared. This is a very handy feature of PHP, though your example shows that it can lead to inconsistencies. For consistent comparison you need the strict operator ===, which compares types, too: null == '' // true null === '' // false
0 == '0'    // true
0 === '0' // false Find more on this in the manual: http://www.php.net/manual/en/types.comparisons.php As this is actually off topic for PEAR, you might want to post in alt.php or comp.lang.php if you wish a further discussion. -- Markus -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanks for that doc pointer Markus (and also the newsgroup references, which
I've just joined). From the docs you pointed me at, I noticed this comment from a user Jan:
Note that php comparison is not transitive: "php" == 0 => true 0 == null => true null == "php" => false
This describes the same issue I was seeing. Livin' and lovin' and learnin'. LFaR.

« previous php.pear.general (#24856) next »