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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael wrote:
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 )

I'm not understanding what you need to work around. What's wrong with using !== false?

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.

The manual page for strpos and any other function that may return 0 or false clearly make this point.

2) My main point is that !== works, so should ===. If !== knows the difference between integer 0 and boolean FALSE, why doesn't ===?

It does, but it also knows the difference between 1 and true, 2 and true, 3 and true, etc.

3) to get feedback from the community and deepen my understanding of PHP.

I'm trying ;)

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux