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

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

 



Robert Cummings wrote:
> On Fri, 2006-11-17 at 02:54 -0700, Michael wrote:
>> This will be my last post on this thread of discussion.
>>
>> Thanks to all who replied, I have it figured out.
>>
>> I guess my only problem with the way the !== and === operators work in this situation is this:
>>
>> Logic dictates that if something evaluates to NOT FALSE it must be TRUE.
>> Regardless of the type, regardless of the species, breed, flavor etc.
> 
> Sure logic dictates that if a return type is confined to the boolean set
> then if it is not false it must be true; however, strpos() may return a
> value from the set of booleans or a value from the set of integers. As


liar liar pants on fire. just to confuse matters (the OP deserves it given the length of the thread):
strpos() may return a boolean false or a value from the set of integers - it will never
ever return true (unless you hack the php source)

friday afternoon nitpicking - which is sometimes referred to as 'ant-***ing' where I come from ;-)

> such, it can have many more return values than only 2.
> 
>> if !== evaluates to TRUE then === should also under the same conditions (all other things being equal)
> 
> Nope. There are two conditions checkeck when using !== and ===. One
> check is the type, the other check is the value. This leaves 4 possible
> scenarios:
> 
>     true  - if an only if the type an the value are the same
>     false - if the type is not the same
>     false - if the value is not the same
>     false - if the type and value are not the same
> 
>> if !== evaluates an integer 0 to TRUE, so should ===, it can't be true and still return a false value.
> 
> An integer 0 is not evaluated to true, a comparison to see if an value
> is exactly equal to the integer 0 may return true.
> 
>>  The !== and === operators work differently, they should be
>> complimentary.
> 
> Actually they work the same... I'll demonstrate:
> 
> <?php
> 
> function equals_equals_equals( $value1, $value2 )
> {
>     if( get_type( $value1 ) == get_type( $value2 )
>         &&
>         $value1 == $value2 )
>     {
>         return true;
>     }
> 
>     return false;
> }
> 
> function not_equals_equals( $value1, $value2 )
> {
>     return !equals_equals_equals( $value1, $value2 );
> }
> 
> ?>
> 
> So there you have it. The implementation of not_equals_equals() uses
> the ! operator on the equals_equals_equals() function and this will give
> you the same behaviour as your currently experiencing and having trouble
> swallowing.
> 
> Cheers,
> Rob.

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