RE: [PHP] Ranges for case statement and a WTF moment.
| From: | Ford, Mike | Date: | Thu, 07 Apr 2011 08:59:51 +0000 |
| Subject: | RE: [PHP] Ranges for case statement and a WTF moment. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-312295@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: David Harkness [mailto:david.h@highgearmedia.com]
> Sent: 06 April 2011 21:08
> To: Richard Quadling; PHP General list
> Subject: Re: [PHP] Ranges for case statement and a WTF moment.
>
> On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling
> <rquadling@gmail.com>wrote:
>
[...]
> > 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
Oh, excellent deduction! I must admit, my first instinct was also that
both numbers should absorb a dot if one of them did, but failed to
realise that .19 would be coerced to "0.19". Just shows how you really
have to think things through, sometimes!
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507 City Campus,
Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm