Re: A really wacky design decision

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

 



On 10/4/09 6:36 AM, "clancy_1@xxxxxxxxxxxx" <clancy_1@xxxxxxxxxxxx> wrote:

>> i might think it ok for (2260 == '226E1') to be true since php would be
>> doing type juggling in a logical left-to-right manner: we start with an
>> integer 2260, next is the juggling comparison operator, then a string, so it
>> might reasonably try to convert the string to an integer and then compare.
>> 
>> but with ('2260' == '226E1'), where both lhs and rhs are already of the same
>> time, it seems elliptical, to say the least, that php should search the
>> types to which it can convert the strings looking for one in which they are
>> equal.
> 
> The order doesn't matter; 2260 == 226e1, and 226e1==2260.

in those two cases, all four operands are integer literals. no juggling is
involved.

and i would have expected the same for ('2260' == '226e1') and ('226e1' ==
'2260') since all operands are string literals and i'd be wrong. (evidently
i'm not alone in making this mistake.)

i get confused reading the manual:

  http://www.php.net/manual/en/language.types.type-juggling.php

says that the context determines if the expression is converted. the example
being the + operator. by definition, it's operands are numeric contexts so
strings are converted. fair enough.

now what about the == operator?

  http://www.php.net/manual/en/language.operators.comparison.php

that page contradicts the previous one because it says that, when an operand
is a string, the determination to convert an operand depends not on the
context but on the specific data _of_ the operand.

i think robert captured the essence of this confusion nicely with:

> 
> On 10/3/09 1:53 PM, "Robert Cummings" <robert@xxxxxxxxxxxxx> wrote:
> 
>> Numeric strings are special :)
>>



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