Re: Ranges for case statement and a WTF moment.

From: Date: Wed, 06 Apr 2011 20:08:20 +0000
Subject: Re: Ranges for case statement and a WTF moment.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-312287@lists.php.net to get a copy of this message
On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling <rquadling@gmail.com>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

« previous php.general (#312287) next »