Re: Re: Bug #51739 tricky string to float conversion
| From: | magic-php at damage dot devloop dot de | Date: | Wed, 31 Aug 2011 21:53:49 +0000 |
| Subject: | Re: Re: Bug #51739 tricky string to float conversion | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314696@lists.php.net to get a copy of this message | ||
Am Mittwoch, 31. August 2011, 20:48:37 schrieb Shawn McKenzie:
> On 08/31/2011 09:03 AM, magic-php@damage.devloop.de wrote:
> > Hi,
> > I have opend Bug #51739 in 2010. It was closed as bogus before my last
> > question was answered. It would be fine to know what you think about
> > that bug.
> > In short:
> > var_dump((float)"8315e839da08e2a7afe6dd12ec58245d");
> > results in float(INF)
> > This is because "8315" is treated as base and
> > "e839da08e2a7afe6dd12ec58245d" is treated as an exponent. My hint that
> > "e839da08e2a7afe6dd12ec58245d" is not a valid exponent was not answered.
> > What do you think about?
> > cheers
> > Daniel
>
> The cast to float is truncating the invalid characters and since your
> string contains a float that is INF (8315e839) before the truncation at
> the "d", then it returns INF. Makes perfect sense.
This is what drives me crazy.
If I use a string in PHP I don't want PHP to cut this string. Either it uses
this string as it is or it gives me an error/warning/false (what ever...). But
silently(!!!) using a small piece of a string is not understandable.
cheers
Daniel