RE: odd behavior of stripos() with === operator *LAST POST*

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

 



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.          |
`------------------------------------------------------------'

-- 
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