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

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

 



On Fri, 2006-11-17 at 00:24 -0700, Michael wrote:
> HEllo all,
> 
> After pulling my hair out for several hours trying to figure out why my code
> wasn't working I built this little test and ran it, the results are interesting
> in the least, and to me, surprising. It is possible that I have done something
> wrong, but I checked and rechecked this in the documentation.
> 
> It appears there is either a problem with the === operator (or my brain...)
> If you don't mind, I'd like to see what you all think.
> 
> I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0
> install is brand new, perhaps I set it up wrong?)
> 
> anyway here is the code I wrote, and the output from it...
> 
>      $found = stripos("abcdefg", "abcdefg");
> echo "found = stripos(\"abcdefg\", \"abcdefg\");\n"
> echo "The value of found is = : $found\n"
> 
> // 1a) --- needle was found in haystack THIS SHOULD BE 
>      if ( $found !== FALSE ) {
>       echo "found does not equal FALSE\n"
>      }
> // 1b) --- needle was found in haystack THIS SHOULD ALSO BE
>      if ($found === TRUE )  {
>       echo "found is equal to TRUE\n"
>      }
> 
> //1c) --- needle was NOT found in haystack THIS SHOULD NOT BE
>      if ( $found === FALSE )  {
>       echo "found is equal to FALSE\n"
>      }
> //1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE
>      if ($found !== TRUE )  {
>       echo "found does not equal TRUE\n"
>      }
> 
>      $found = stripos("abcdefg", "tuvwxyz");
> 
> echo "\$found = stripos(\"abcdefg\", \"tuvwxyz\");<br>\n"
> echo "The value of found is = : $found\n"
> 
> //2a) --- needle was found in haystack  THIS SHOULD NOT BE
>      if ( $found !== FALSE ) {
>       echo "found does not equal FALSE\n"
>      }
> //2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE
>      if ($found === TRUE )  {
>       echo "found is equal to TRUE\n"
>      }
> 
> //2c) --- needle was NOT found in haystack THIS SHOULD BE
>      if ( $found === FALSE )  {
>       echo "found is equal to FALSE\n"
>      }
> //2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE
>      if ($found !== TRUE )  {
>       echo "found does not equal TRUE\n"
>      }
> 
> the output:
> 
> $found = stripos("abcdefg", "abcdefg");
> The value of found is = : 0 
> 
> found does not equal FALSE   //this is from section 1a) of the code
> 
> found does not equal TRUE    //this is from section 1d) of the code
>                              // I expected the code from 1b) to be executed
> 
> $found = stripos("abcdefg", "tuvwxyz");
> The value of found is = : 
> 
> found is equal to FALSE      //this is from section 2c) of the code
> 
> found does not equal TRUE    //this is from section 2d) of the code
> 
> I have underlined the output I am interested in...

You did??? Where?

> How can the variable $found be both TRUE and FALSE at the same time?

None of your output above indicates that it is both equal to TRUE and
FALSE at the same time. It does indicate that $found does NOT equal TRUE
and does NOT equal FALSE at the same time and that is because it
returned the integer value 0 which is the location of the string in the
haystack.

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