php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80101 Cast to an integer should emit warning if outside the range
Submitted: 2020-09-14 11:30 UTC Modified: -
From: michael dot vorisek at email dot cz Assigned:
Status: Open Package: *General Issues
PHP Version: 7.4.10 OS: any
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
28 + 12 = ?
Subscribe to this entry?

 
 [2020-09-14 11:30 UTC] michael dot vorisek at email dot cz
Description:
------------
if float or string is casted to an integer type and it evaluates to a number outside the max. range, at least warning should be emitted

Test script:
---------------
var_dump((int) (PHP_INT_MAX + 1));    // int(-9223372036854775808)
var_dump((int) (PHP_INT_MAX + 10));   // int(-9223372036854775808)
var_dump((int) (PHP_INT_MAX + 2000)); // int(-9223372036854773760)
var_dump((int) INF);                  // int(0)

https://3v4l.org/fgeYU

Expected result:
----------------
all 4 cases must emit at least a warning, similar to 1/0 division


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 26 22:03:33 2021 UTC