php.net |  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
Votes:8
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'...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-31 20:30 UTC] jani@php.net
-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.


--TEST--
// phpt file: request10657.phpt
Request #10657	Add warning about overflow to settype()
--FILE--
<?php
// overflow integer
$foo = '11111111112';
settype($foo, "integer");
var_dump($foo);

// string -> integer
$bar = 'fjsfjsdh';
settype($bar, "integer");
var_dump($bar);
?>
--EXPECT--
int(11111111112)
int(0)
 [2014-11-06 19:28 UTC] requinix@php.net
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] heiglandreas@php.net
-Status: Open +Status: Feedback
 [2017-01-20 17:05 UTC] heiglandreas@php.net
Is this still relevant?
 [2017-01-20 17:30 UTC] requinix@php.net
-Status: Feedback +Status: Open -Package: *General Issues +Package: Variables related -PHP Version: * +PHP Version: 7.1.1
 [2017-01-20 17:30 UTC] requinix@php.net
settype is not issuing warnings.

https://3v4l.org/LSBfU - numeric string >PHP_INT_MAX to int
https://3v4l.org/LT5dX - non-numeric string to int
 [2017-01-20 17:43 UTC] nikic@php.net
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] pollita@php.net
@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] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-07-23 02:12 UTC] kalle@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 23:01:25 2019 UTC