|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74167 intval() considers string input as integer if string contains e(e notation)
Submitted: 2017-02-25 18:10 UTC Modified: 2017-02-25 19:06 UTC
From: stephin at stephin dot in Assigned:
Status: Not a bug Package: Strings related
PHP Version: 7.1.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
7 + 42 = ?
Subscribe to this entry?

 [2017-02-25 18:10 UTC] stephin at stephin dot in
php -r "echo intval('1e10');"

expected output: 1
actual output:  10000000000

i have tested this in some of other previous version series and found only php 7.1.x have this bug. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-25 18:22 UTC] spam2 at rhsoft dot net
this is for most cases a bugfix where before PHP7.1 when something returned scientific notation because of 0.0000000000001 you got weird results and lost data 

i have some workarounds in several scripts to prevent that which are ugly

if(strpos($out, 'E') || strpos($out, 'e'))
 $out = rtrim(number_format((float)$out, 20), '0');

Numerical string conversions now respect scientific notation
Integer operations and conversions on numerical strings now respect scientific notation. This also includes the (int) cast operation, and the following functions: intval() (where the base is 10), settype(), decbin(), decoct(), and dechex()
 [2017-02-25 18:30 UTC]
-Status: Open +Status: Not a bug
 [2017-02-25 18:30 UTC]
As noted, this was a deliberate change, and it was part of an improvement to numeric strings as a whole.
 [2017-02-25 18:41 UTC] stephin at stephin dot in
how can we call this string(354e3318D2174C4196I7371p2214T3183F6594X2108) as numerical string?
 [2017-02-25 18:54 UTC] stephin at stephin dot in
php 7.1.2

php -r "echo intval('354e3318D2174C4196I7371p2214T3183F6594X2108');"

output: 0

why should it be 0?  

other previous version series

php -r "echo intval('354e3318D2174C4196I7371p2214T3183F6594X2108');"

output: 354
 [2017-02-25 19:06 UTC]
The numeric value extracted is 354e3318, which is float(INF). Converting that to int will give 0.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 01:01:33 2024 UTC