Re: Equivalency of null
| From: | Markus Ernst | Date: | Tue, 08 Aug 2006 07:33:56 +0000 |
| Subject: | Re: Equivalency of null | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24855@lists.php.net to get a copy of this message | ||
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' // true0 === '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