Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78166 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59614 invoked from network); 21 Oct 2014 00:49:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2014 00:49:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.244 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.244 imap1-3.ox.privateemail.com Received: from [198.187.29.244] ([198.187.29.244:39624] helo=imap1-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/F2-42514-98DA5445 for ; Mon, 20 Oct 2014 20:49:13 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 9FDC8B00091; Mon, 20 Oct 2014 20:49:10 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QILCyH2sdsTT; Mon, 20 Oct 2014 20:49:10 -0400 (EDT) Received: from oa-res-26-28.wireless.abdn.ac.uk (oa-res-26-28.wireless.abdn.ac.uk [137.50.26.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 052BEB00085; Mon, 20 Oct 2014 20:49:09 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <5445A9AE.2060001@sugarcrm.com> Date: Tue, 21 Oct 2014 01:49:07 +0100 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <5445A9AE.2060001@sugarcrm.com> To: Stas Malyshev X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: ajf@ajf.me (Andrea Faulds) Hi! > On 21 Oct 2014, at 01:32, Stas Malyshev = wrote: >=20 > The main problem that happened with scalar typing RFC remains here: > third set of rules for casting types. Of course, since it's "just" > functions and not language constructs, we can have a set of functions > for any set of casting rules anybody wants. But I think it's still the > same problem here - having three sets of casting rules is not good. We have more than three sets of casting rules, but at least these ones = are rather straightforward. > Wait, we actually already have FILTER_VALIDATE_INT and > FILTER_VALIDATE_FLOAT, Actually, to_int is very close to FILTER_VALIDATE_INT, and I=E2=80=99m = not sure, but I think to_float may be close to FILTER_VALIDATE_FLOAT. = The main difference with integers is rejection of whitespace and = toString-able objects. > so that would be the fourth set of rules, and the > second set of validation rules, despite already having an extension > specially dedicated to filtering and validation. I think we should not > multiply entities needlessly - if we need some different validation > primitives, why not add them to filter, for example The main point of the RFC is to add casting functions as an alternative = to the built-in explicit casts. Currently, the easiest way to convert to = an integer is (int), but this is quite dangerous as it performs no = validation whatsoever and cannot fail. to_int() and the like are = intended to be just as convenient as an explicit cast, so that doing the = safer thing (failing on garbage input) is not any more difficult. The = hope is that the lazy developer will use is_int() instead of (int) when = they need to explicitly cast, and avoid the problems of the latter. -- Andrea Faulds http://ajf.me/