Re: Ranges for case statement and a WTF moment.

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

 



On 6 April 2011 21:08, David Harkness <david.h@xxxxxxxxxxxxxxxxx> wrote:
> On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling <rquadling@xxxxxxxxx>
> wrote:
>>
>> php -r "var_dump(10...19);"
>>
>> Interesting output ...
>>
>> string(6) "100.19"
>>
>> And that took me a little while to work out.
>>
>> It's all to do with PHP's type juggling.
>>
>> 10...19
>>
>> What I'm not sure is why the middle empty string is output as 0.
>>
>> "10" . . ".19" becomes "10" . "0" . ".19" which becomes "100.19"
>
> My guess is that PHP parses this as
> Â Â 10<decimal-point> <dot-operator>Â<decimal-point>19
> Because the dot operator requires strings, PHP converts both numbers to
> strings as
> Â Â '10' <dot-operator> '0.19'
> which becomes your
> Â Â 100.19
> You can see this with
> Â Â php > echo (string) 10.
> Â Â 10
> Â ÂÂphpÂ> echo (string) .19
> Â Â 0.19
> David
>

Aha! Yes. That makes a LOT more sense.

Excellent deduction.

So. Not a bug at all. Just a really weird sequence.

And obviously, spaces and more dots can't work.

Richard.
-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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