Bug #67478 [Nab]: Strange behaviour on casting to integer

From: Date: Fri, 20 Jun 2014 05:05:35 +0000
Subject: Bug #67478 [Nab]: Strange behaviour on casting to integer
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186268@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67478&edit=1 ID: 67478 User updated by: upyx dot 00 at gmail dot com Reported by: upyx dot 00 at gmail dot com Summary: Strange behaviour on casting to integer Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: linux 64 PHP Version: 5.5.13 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-06-19 17:49:44] 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-19 12:42:41] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67478&edit=1

« previous php.bugs (#186268) next »