php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67478 Strange behaviour on casting to integer
Submitted: 2014-06-19 12:42 UTC Modified: 2014-06-20 05:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: upyx dot 00 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.13 OS: linux 64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: upyx dot 00 at gmail dot com
New email:
PHP Version: OS:

 

 [2014-06-19 12:42 UTC] upyx dot 00 at gmail dot com
Description:
------------
Returns huge negative value when casting float value greater then PHP_INT_MAX to integer.

Test script:
---------------
$ php -r 'var_dump(9223372036854775808);'
double(9.2233720368548E+18)
$ php -r 'var_dump((int)9223372036854775808);'
int(-9223372036854775808)
$ php -r 'var_dump((int)9223372036854775809);'
int(-9223372036854775808)

Expected result:
----------------
double(9.2233720368548E+18)
ERROR (or cut to PHP_INT_MAX, but not negative value!)
ERROR

Actual result:
--------------
double(9.2233720368548E+18)
int(-9223372036854775808)
int(-9223372036854775808)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-19 17:49 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-06-19 17:49 UTC] aharvey@php.net
Float -> integer conversion being undefined when the float is beyond PHP_INT_MAX is documented behaviour: http://php.net/manual/en/language.types.integer.php#language.types.integer.casting.from-float

In practice, this is to do with PHP using signed integers internally, but the official advice is "don't do that".
 [2014-06-20 05:05 UTC] upyx dot 00 at gmail dot com
Ok! It was documented...
But this behaviour is bad.
If it doesn't work need trow exception, error or so on. But not quit break data.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC