Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79015 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90231 invoked from network); 19 Nov 2014 22:05:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2014 22:05:58 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.245 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.245 imap11-3.ox.privateemail.com Received: from [198.187.29.245] ([198.187.29.245:59751] helo=imap11-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/E1-12113-6441D645 for ; Wed, 19 Nov 2014 17:05:58 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 585318800E6; Wed, 19 Nov 2014 17:05:55 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5mp4THr7gUri; Wed, 19 Nov 2014 17:05:55 -0500 (EST) Received: from oa-res-27-29.wireless.abdn.ac.uk (oa-res-27-29.wireless.abdn.ac.uk [137.50.27.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id A44418800F5; Wed, 19 Nov 2014 17:05:54 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Wed, 19 Nov 2014 22:05:52 +0000 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <67A212FE-0051-4DEA-B1BC-AB3CA16CF4B5@ajf.me> References: To: Levi Morrison X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [VOTE][RFC] Safe Casting Functions From: ajf@ajf.me (Andrea Faulds) > On 19 Nov 2014, at 21:57, Levi Morrison wrote: >=20 >> Since some things might have changed since you last read the RFC, I = encourage you to read through it again. If there are any questions which = have not yet been covered on the mailing list, feel free to ask them. >=20 > - The RFC does not address how this is different from > FILTER_VALIDATE_* from ext/filter. I know there was a mention of this > on the mailing list, but the RFC should say why a tool that already > exists to solve this kind of problem is insufficient, especially when > it is enabled by default. Yes, I suppose that=E2=80=99s a failing of it just now. But to address = this: 1) It throws exceptions 2) It is much shorter and more convenient (which is important if we=E2=80=99= re to discourage (int), (float) use) 3) to_/try_int() and to_/try_float() don't convert the argument to a = string in order to convert > - PHP suffers a lot from function bloat and this RFC provides > multiple functions that do the same thing but differ only in how they > handle errors. A simple validation of "can this be safely cast to an > integer without dataloss?" avoid the issue entirely and would be fewer > functions. No, no it would not avoid the issue. We had this before with error = return values, which are essentially the same as your proposal. People = didn=E2=80=99t like only covering one use case. I didn=E2=80=99t like = that. Yes, you can write a wrapper function for a validation function = that throws an exception. You also could write one for the error return = value function. It=E2=80=99s equally objectionable. Secondly, merely =E2=80=9Cvalidating=E2=80=9D and not converting means = you must then convert after validating. However, the process of = validating involves converting it. So you=E2=80=99re doing the same = thing twice, essentially, for no conceivable gain. I=E2=80=99ve said it before, I=E2=80=99ll say it again. There=E2=80=99s = nothing which is really any better about just having try_int() return = TRUE on success rather than the converted value, and not having = to_int(). But I=E2=80=99ve had this argument several times now, so I=E2=80=99m not = going to have it again on the mailing list. This will be my last word on = that suggestion. -- Andrea Faulds http://ajf.me/