|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70714 Type change when adding to PHP_INT_MAX
Submitted: 2015-10-14 17:52 UTC Modified: 2015-10-14 17:56 UTC
From: geggleto at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 7.0.0RC4 OS: Linux
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:
20 + 24 = ?
Subscribe to this entry?

 [2015-10-14 17:52 UTC] geggleto at gmail dot com
When adding to PHP_INT_MAX the PHP internals switch the type from INT to FLOAT.

This should be documented.

The real problem is when you attempt to cast it back to int.


Test script:
$min = PHP_INT_MAX + 1;

$newMin = (int)$min;


Expected result:
I expect that a Exception or Warning would be raised.
E_WARNING | E_NOTICE would be acceptable, I would use E_WARNING

I think that this code should register 2 warnings.

1) When you are overflowing the integer, and the engine is recasting to float.

2) When you are casting from Float to Int and the cast will lose data.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-14 17:56 UTC]
-Status: Open +Status: Not a bug
 [2015-10-14 17:56 UTC]
> If PHP encounters a number beyond the bounds of the integer type, it will be
> interpreted as a float instead. Also, an operation which results in a number
> beyond the bounds of the integer type will return a float instead.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 03:01:30 2024 UTC