php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74480 Cast error from String to Int
Submitted: 2017-04-20 14:36 UTC Modified: 2017-04-20 14:41 UTC
From: philipp dot kremer at prolead-technologies dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.4 OS: Windows 10
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: philipp dot kremer at prolead-technologies dot de
New email:
PHP Version: OS:

 

 [2017-04-20 14:36 UTC] philipp dot kremer at prolead-technologies dot de
Description:
------------
Type cast from String to Int are not working correctly.

System windows 10 64bit
PHP 7.1.4 32bit

> php -v
PHP 7.1.4 (cli) (built: Apr 11 2017 20:07:48) ( NTS MSVC14 (Visual C++ 2015) x86 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

> php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
filter
gettext
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
mysqlnd
openssl
pcre
PDO
pdo_mysql
Phar
readline
Reflection
session
shmop
SimpleXML
soap
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]



Test script:
---------------
<?php
$mandant_id = "2147483647";
var_dump($mandant_id, (int)$mandant_id);

$mandant_id = "122994595930";
var_dump($mandant_id, (int)$mandant_id);

Expected result:
----------------
string(10) "2147483647"
int(2147483647)
string(12) "122994595930"
int(122994595930)

or

string(10) "2147483647"
int(2147483647)
string(12) "122994595930"
float(122994595930)


Actual result:
--------------
string(10) "2147483647"
int(2147483647)
string(12) "122994595930"
int(2147483647)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-20 14:41 UTC] daverandom@php.net
-Status: Open +Status: Not a bug
 [2017-04-20 14:41 UTC] daverandom@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

(int) casts explicitly cast to the integer data type.

The expected behaviour in this case is that the result will be an integer, a floating point result would be extremely unexpected and cause serious problems for many use cases.

It could possibly be argued that an overflow here should produce an exception, however that is beyond the scope of a simple bug report as this would have far reaching and likely controversial implications.
 [2017-04-20 15:28 UTC] spam2 at rhsoft dot net
are there no 64bit builds for windows or why do you use a 32bit PHP on a 64bit Windows? please let die 32bit at all.....

[harry@srv-rhsoft:~]$ php -v
PHP 7.1.4 (cli) (built: Apr 19 2017 17:54:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

php > $mandant_id = "2147483647"; var_dump($mandant_id, (int)$mandant_id);
string(10) "2147483647"
int(2147483647)

php > $mandant_id = "122994595930"; var_dump($mandant_id, (int)$mandant_id);
string(12) "122994595930"
int(122994595930)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 13:00:01 2026 UTC