Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56432 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42923 invoked from network); 19 Nov 2011 14:47:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2011 14:47:06 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:35519] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/34-17432-661C7CE4 for ; Sat, 19 Nov 2011 09:47:03 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 702B67000449 for ; Sat, 19 Nov 2011 14:46:59 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id WvJxIfAxY+Zv for ; Sat, 19 Nov 2011 14:46:59 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 2FDBD7000430 for ; Sat, 19 Nov 2011 14:46:59 +0000 (WET) Received: from cataphract.cata.lo.geleia.net (a79-168-248-114.cpe.netcabo.pt [79.168.248.114]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 0C94320002DA for ; Sat, 19 Nov 2011 14:46:59 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Sat, 19 Nov 2011 14:46:30 -0000 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.52 (Win32) Subject: Re: [PHP-DEV] PHP Integer Bug From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sat, 19 Nov 2011 13:46:35 -0000, Paul Dragoonis wrote: > [...] > > ---- CODE --- > $s = "2433078805"; > var_dump($s); > var_dump((int) $s); exit; > > ----- EXPECTED ----- > string(10) "2433078805" int(2433078805) > > ----- ACTUAL ----- > string(10) "2433078805" int(2147483647) > > Anthony has already explained the problem, but I can't find this documented anywhere. The manual says a conversion from a float outside the integer boundaries results in undefined behavior ( http://php.net/manual/en/language.types.integer.php#language.types.integer.casting ) and that "if the string does not contain any of the characters '.', 'e', or 'E' and the numeric value fits into integer type limits (as defined by PHP_INT_MAX), the string will be evaluated as an integer. In all other cases it will be evaluated as a float." ( http://php.net/manual/en/language.types.string.php#language.types.string.conversion ). None of these seems to apply here, though perhaps from combining the two we could conclude the behavior is undefined. Internally, the behavior is also not explicitly laid out; it follows from the behavior of strol. This adds a notice: Index: Zend/zend_operators.c =================================================================== --- Zend/zend_operators.c (revision 319548) +++ Zend/zend_operators.c (working copy) @@ -353,7 +353,11 @@ { char *strval = Z_STRVAL_P(op); + errno = 0; Z_LVAL_P(op) = strtol(strval, NULL, base); + if (errno == ERANGE) { + zend_error(E_NOTICE, "Value outside integer bounds"); + } STR_FREE(strval); } break; -- Gustavo Lopes