Re: odd behavior of stripos() with === operator

From: Date: Fri, 17 Nov 2006 09:29:24 +0000
Subject: Re: odd behavior of stripos() with === operator
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-244779@lists.php.net to get a copy of this message
At 02:10 AM 11/17/2006 , Stut wrote: >Michael wrote: >> Ok, picking gnits... >> I should have said NOT true and NOT false at the same time. >> As for the return of the integer 0.. >> The documentation indicates that the === and !== operators take this into account in fact >> there is a specific example in the manual. >> >> My point here is that if !== works , why does === not? >> > >I think you need to re-read the docs for ===. > > 0 !== false > > 0 == false > > 1 == true > > 1 !== true > >only... > > false === false > >and > > true === true > >The === and !== check both value and type, so 0 and false are different. > >Hope that helped. > >-Stut > >-- Thanks for your reply Stut. I understand that the integer 0 and FALSE are different and I read the manual so many times my head hurts, heh. There are a few ways to work around this, probably more than I know. (according to the documentation for strrpos() you could test the return from stripos() for is_bool before using it), or (perhaps, cast the return from stripos() to a boolean, although integer 0 probably casts to false :/, I honestly didn't test this {see >>>}), or (easiest solution...just suck up and use !== FALSE all the time :D ) My point in posting this was threefold, 1) to help others who may not know that stripos() returns an INTEGER 0 when the needle is found at the beginning of haystack, and/or don't realize the implications of that. 2) My main point is that !== works, so should ===. If !== knows the difference between integer 0 and boolean FALSE, why doesn't ===? 3) to get feedback from the community and deepen my understanding of PHP. So, I thank you very much for your reply :) Regards, Michael

« previous php.general (#244779) next »