Re: PHP number auto-converting doesn't work for negative #'s without a leading digit
| From: | Justin Patrin | Date: | Wed, 09 Feb 2005 15:56:37 +0000 |
| Subject: | Re: PHP number auto-converting doesn't work for negative #'s without a leading digit | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36095@lists.php.net to get a copy of this message | ||
On Wed, 9 Feb 2005 07:47:01 -0800 (PST), Jesus M. Castagnetto
<jcastagnetto@yahoo.com> wrote:
> Autoconversions in any language are not always perfect (in particular from
> string representations to numbers), that is why I tend to cast in my own code.
>
> In this case, it might be a question of tunning the Zend parser to recognize
> the abbreviated construct you show as a valid float, although strictly it
> should have the zero in front (it is just customary to sometimes omit it).
>
> Also, you might want to reclassify it as a Zend Engine or Scripting Engine bug,
> as the decision as to whether something looks like a float is done in places
> like: php-src/ZendEngine2/zend_operators.h:is_numeric_string()
It's already fixed in the snapshot, so no need to reclassify. The
reason I had this problem was that Oracle returned those strings for a
NUMBER column. I *should* have casted it, but I have assumed with PHP
it handles them correctly.
>
> Cheers.
>
> --- Justin Patrin <papercrane@gmail.com> wrote:
>
> > Just thought you all might like to know:
> > http://bugs.php.net/bug.php?id=31889
> >
> > This is a pretty simple bug which affects scripts which assume PHP
> > will convert a string to a number automatically. It will except for
> > strings such as: "-.55" with no leading digit. Using (float) before
> > the string works fine, but the auto-conversion doesn't. See the second
> > reproduce code in the bug for an example (forget the first one, I
> > screwed that one up :-/ ).
> >
--
Justin Patrin