RE: [PHP] odd behavior of stripos() with === operator *LAST POST*
| From: | Robert Cummings | Date: | Tue, 21 Nov 2006 00:41:38 +0000 |
| Subject: | RE: [PHP] odd behavior of stripos() with === operator *LAST POST* | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244927@lists.php.net to get a copy of this message | ||
On Mon, 2006-11-20 at 17:23 -0700, Michael wrote:
>
> in other words do not try to test for === TRUE, only test for !== FALSE
>
> and the warning in the manual ...
> Warning
> This function may return Boolean FALSE, but may also return a non-Boolean value
> which evaluates to FALSE, such as 0 or "". Please read the section on Booleans
> for more information. Use the === operator for testing the return value of this
> function.
>
> should read "...use the !== operator for testing..."
>
> because if you use ===, you will NOT get the expected results if needle is
> found in haystack at position 0. However, !== will always work correctly.
That REALLY depends on what you want to test:
<?php
if( strpos( 'abcdef', 'abc' ) === 0 )
{
echo <<<_
;)
_;
}
?>
Granted the context where they write === is quite ambiguous :)
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'