|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10657 Add warning about overflow to settype()
Submitted: 2001-05-04 02:50 UTC Modified: 2017-07-23 02:12 UTC
Avg. Score:2.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: tf at tfromm dot com Assigned: kalle (profile)
Status: Closed Package: Variables related
PHP Version: 7.1.1 OS: linux
Private report: No CVE-ID: None
 [2001-05-04 02:50 UTC] tf at tfromm dot com
if i use settype($foo, "integer") with an value for $foo
alike '11111111112' 
settype() returns successfull type setting and changes the 
value to something like that '2147483647'

could it be possible that settype produces a warning, if 
an value larger that the supported bitvalue of the current 
system is and/or changes the value to 0 alike settype() on 
a striong like this 'fjsfjsdh'...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-31 20:30 UTC]
-Summary: settype() with larger than 32bit values +Summary: Add warning about overflow to settype() -Package: Feature/Change Request +Package: *General Issues -PHP Version: 4.0.4 +PHP Version: *
 [2014-11-05 20:55 UTC] edgar dot r dot sandi at gmail dot com
This script was created and tested in PHP 5.5.8 and PHP 5.6.2 with both situations described in this Request and the outputs were correct with expected.

This request can be closed.

// phpt file: request10657.phpt
Request #10657	Add warning about overflow to settype()
// overflow integer
$foo = '11111111112';
settype($foo, "integer");

// string -> integer
$bar = 'fjsfjsdh';
settype($bar, "integer");
 [2014-11-06 19:28 UTC]
Can't be closed quite yet, Edgar: you're using a 64-bit PHP which can handle 11111111112 as an integer. Try with 9999999999999999999.
 [2017-01-20 17:05 UTC]
-Status: Open +Status: Feedback
 [2017-01-20 17:05 UTC]
Is this still relevant?
 [2017-01-20 17:30 UTC]
-Status: Feedback +Status: Open -Package: *General Issues +Package: Variables related -PHP Version: * +PHP Version: 7.1.1
 [2017-01-20 17:30 UTC]
settype is not issuing warnings. - numeric string >PHP_INT_MAX to int - non-numeric string to int
 [2017-01-20 17:43 UTC]
settype() behaves the same as an (int) cast. I highly doubt that we'd add such a warning for (int) casting.
 [2017-03-14 03:25 UTC]
@nikic I disagree.  It seems like warnings *should* be added for these overflow on cast cases.  It's not BC, but the existing behavior could hardly be described as "working as reasonably expected".
 [2017-03-14 03:48 UTC] spam2 at rhsoft dot net
NO there SHOUL DNOT be added warnings - how do you imagine to handle warnings triggered by <?=(int)$_GET['bla']?> when it exceeds PHP_INT_MAX? there are people which running E_ALL in production and warnings which can be properly fixed except add again @ with all it's dirt and overhead are not helpful
 [2017-07-23 02:12 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-07-23 02:12 UTC]
I agree that there should not be any warnings, if anything this should go through the RFC process instead of the bug tracker
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 22:03:39 2021 UTC