Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86178 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60848 invoked from network); 12 May 2015 19:57:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2015 19:57:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:37822] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/B3-41925-B3B52555 for ; Tue, 12 May 2015 15:57:48 -0400 Received: by widdi4 with SMTP id di4so29693302wid.0 for ; Tue, 12 May 2015 12:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=cuHncW2SU4X/gO86mrHkEu2bA25ETZUB50tX4up29pI=; b=xaS7/NOGNV5GBzTc0jxatjgXa4GphebEXZDNZyiOd6bSIrb6amlAVb9swj4sPYqBT9 f6s7FaQrc2BHzSf3IPkPr/ct0rmOwBrbHYtD8kU3qk2RWinL4oyqkkdeBKdRp31eYOgh oMApfJh6XhcNB5ePn4wTXSjRTNhDZ4PmFybGffxGtP7NkZjcu52XCOFj0qe67jhhLKbd K48GiFQQrRJed3BP13QRp5NmyAQk9Ee0fj9ciMjTm5TYF/MFS2CPsiW8mBiZZ9cbTljX TfFathr4yMZFpoKNuIQQdued31JWz1f5MJRxS9540i/L10iRj699P9zE8XQKK97bo6xp 3ySQ== X-Received: by 10.194.204.230 with SMTP id lb6mr32825199wjc.63.1431460664867; Tue, 12 May 2015 12:57:44 -0700 (PDT) Received: from [192.168.0.6] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id f8sm4408354wiy.7.2015.05.12.12.57.43 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 May 2015 12:57:44 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: <5552540C.9000205@lsces.co.uk> References: <5552540C.9000205@lsces.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 May 2015 20:57:33 +0100 To: internals@lists.php.net Message-ID: <1C9DBFFC-7B6D-470B-B706-7A6B0938C67A@gmail.com> Subject: Re: [PHP-DEV] is_digits() and digits type From: rowan.collins@gmail.com (Rowan Collins) On 12 May 2015 20:27:08 BST, Lester Caine wrote: >On 12/05/15 19:55, Rowan Collins wrote: >> For instance, valid input for a 64-bit signed integer in a database >could include: >> - any PHP native integer (assuming nobody builds with 128-bit ints!) >> - any string consisting of all digits, such that when interpreted as >an integer the value won't exceed 2^64-1 >> - any string consisting of a '-' followed by digits, such that the >magnitude of the integer interpretation wouldn't exceed 2^64 >> - any PHP float with no fractional part, maybe capped to a magnitude >less than 2^53 for safety > >BUT >In INTEGER in a database is 32 bit and will remain 32 bit, just as >SMALLINT is 16 bit ... 64 bit is BIGINT and so the whole concept of >simply ignoring 32 bit and handling them instead as 64bit is wrong! Nobody is "ignoring 32-bit". If you want to validate that a variable will fit in a 32-bit signed integer, or a 16-bit unsigned one, or whatever else, you need to range-check it as above. Just as you would validate a variable which you expected to contain an email address before you used it in an SMTP header. Type hints are not intended for validating data that is entering or leaving PHP from or to other systems, they are only relevant when passing data from one part of a PHP system to another. On any given install of PHP, two libraries communicating with each other by function calls will agree on a definition of "int", because they are in the same process, and that is all that is needed for an "int" type hint to be meaningful. Regards, -- Rowan Collins [IMSoP]