Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86183 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71973 invoked from network); 12 May 2015 21:33:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2015 21:33:10 -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.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:33311] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/85-41925-39172555 for ; Tue, 12 May 2015 17:33:09 -0400 Received: by wief7 with SMTP id f7so122099651wie.0 for ; Tue, 12 May 2015 14:33:03 -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=l3DmKU2FHIAEKcl5/+l4GD47JDb9idhd7mtDRC4vqkQ=; b=G6wSxTN5AOMQqL7YG6NfaE8FZkhf8cmAPyA24kyzb/VDxCkRltktOvNRvpBEWWssgo d3v3oY30xvdQvGGD6IyC55YwTOqQMD85RuNRFNW9lwAgZLnBgxPuegUFokD4UdtQkn4w i+VPr31WvXYWXXSlw/mh/cQdy+QZjaYTvea1uQvqhFgnAirm8en7+5t/iotCAMbgqIKM k22w3rA2cLn4nEoAe8FnjHeO/g5cAJNfJYy7pGH+t77x0hAv/JEh8P8XMDDH97wJumIK GFK2xyHMIrCwyRodSBT44d9yHNRrQDRg+AbB2qSxHZzRfYIS/VCdF8wm90xTKYjIf06s doTA== X-Received: by 10.180.208.99 with SMTP id md3mr8651471wic.34.1431466383744; Tue, 12 May 2015 14:33:03 -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 xb3sm26495310wjc.38.2015.05.12.14.33.02 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 May 2015 14:33:03 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: <55526363.1090105@lsces.co.uk> References: <5552540C.9000205@lsces.co.uk> <1C9DBFFC-7B6D-470B-B706-7A6B0938C67A@gmail.com> <55526363.1090105@lsces.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 May 2015 22:32:55 +0100 To: PHP internals Message-ID: Subject: Re: [PHP-DEV] is_digits() and digits type From: rowan.collins@gmail.com (Rowan Collins) On 12 May 2015 21:32:35 BST, Lester Caine wrote: >On 12/05/15 20:57, Rowan Collins wrote: >> 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. > >I think that perhaps this is a key point that needs to be fully >documented before PHP7 is released. That type hints are essentially NOT >to be used for data validation may not be obvious to many who are >planning to 'convert' to using them? Perhaps, but this is exactly the same purpose type hints have in other languages, AFAIK. Types in different systems have different meanings, and no one language can remove those differences. >However I still don't see how one one can handle data handed over >internally without also providing a mechanism to ensure the right range >of value is maintained through the system. If a library produces >results >that are out of range of the target channel then simply establishing >that it's a valid number is of limited use. It is of limited use in some situations, yes. Knowing that a value is an integer as defined by PHP is entirely sufficient if the task at hand is to manipulate it mathematically as an integer. Knowing that a value is a string is of limited value if the task at hand is to use it as an e-mail address. Database input of integers is more similar to the second case than the first. >It IS the handling of data validation as a central service that is >needed, and why would one not then use that for the internal data >handling as well? It may be that that is what YOU need, but that doesn't make other people's needs irrelevant. It is already possible to pass around, and type hint for, any class of object, so you could for instance have a DatabaseID class. PHP's lack of operator overloading makes that less appealing, perhaps, but it would work. In some languages, you can simply declare "range" or "domain" types, which are scalar types annotated with upper and lower bounds, or other limits. Ada apparently encourages this, for instance. The problem with doing so in PHP is that a variable's type is not fixed or declared, so in something as simple as $a = $b + 1, should $a have the same range as $b or not? Of course, if you want "PHP, but with a stricter type system", then you can always use Hack. :) Regards, -- Rowan Collins [IMSoP]