php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: geggleto at gmail dot com
New email:
PHP Version: OS:

 

 [2015-10-14 17:52 UTC] geggleto at gmail dot com
Description:
------------
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.

Reference:
https://github.com/paragonie/random_compat/issues/50#issuecomment-148128683



Test script:
---------------
<?php
$min = PHP_INT_MAX + 1;
var_dump($min);

$newMin = (int)$min;

var_dump($newMin);

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:
--------------
float(9.2233720368548E+18)
int(-9223372036854775808)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-14 17:56 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-10-14 17:56 UTC] requinix@php.net
http://php.net/manual/en/language.types.integer.php#language.types.integer.overflow
> 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: Thu Dec 26 10:01:29 2024 UTC