php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10437 casting is not consistent
Submitted: 2001-04-22 04:06 UTC Modified: 2001-08-12 20:24 UTC
From: goba@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: win2k
Private report: No CVE-ID: None
 [2001-04-22 04:06 UTC] goba@php.net
Casting is not consistent with doubles:

$foo = "5.31abc";

$foo2 = (double) $foo;
$foo3 = $foo + 0;

The first gives 5.31 the second gives 5,
although it should notice the full 5.31 number
in the string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-19 17:22 UTC] jeroen@php.net
Strange indeed.

There are explicit casts (either to double or to int)
and implicit casts.

You can view upon the latter one as a (number) cast,
it casts to a number, maybe int, maybe float.

In that cast strings like '5.31abc' are not detected as double, (invaled numbers after the dot) so integer parsing takes place, which yields the int 5.

This should be corrected in Zend.
 [2001-05-19 17:42 UTC] jeroen@php.net
From line 117 of zend_operators.c it says: If the string is nor an exact double, nor an exact long, do strtol on it.

There you should first try strtod, see if it parses more chars that strtol...

And I don't know anything about C!
 [2001-08-12 20:24 UTC] zeev@php.net
Fixed in the CVS (will be a part of 4.0.7).
Thanks for the bug report!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC