Bug #70714 [NEW]: Type change when adding to PHP_INT_MAX

From: Date: Wed, 14 Oct 2015 17:52:31 +0000
Subject: Bug #70714 [NEW]: Type change when adding to PHP_INT_MAX
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196608@lists.php.net to get a copy of this message
From:             geggleto at gmail dot com
Operating system: Linux
PHP version:      7.0.0RC4
Package:          Variables related
Bug Type:         Bug
Bug description:Type change when adding to PHP_INT_MAX

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)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=70714&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70714&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70714&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70714&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70714&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70714&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70714&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70714&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70714&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70714&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70714&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70714&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70714&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70714&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70714&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70714&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70714&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70714&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70714&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70714&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70714&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#196608) next »