|  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: 2021-11-05 18:56 UTC
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:


 [2020-09-14 11:30 UTC] michael dot vorisek at email dot cz
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)

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-05 18:56 UTC]
I'd rather have bigints (<>).
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 03:01:29 2023 UTC