Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78255 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16453 invoked from network); 22 Oct 2014 22:23:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2014 22:23:22 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.182 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.220.182 mail-vc0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:54436] helo=mail-vc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/39-63701-95E28445 for ; Wed, 22 Oct 2014 18:23:22 -0400 Received: by mail-vc0-f182.google.com with SMTP id la4so2666356vcb.13 for ; Wed, 22 Oct 2014 15:23:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=h3IkXQ2p/xUc7/AWnT9fcPcElKHayyvNoHuAjeLXZMA=; b=IRrP6pg+edqCP/zpQdj72lx5NFTgLsyRM6cBHrcr6Juc8aHAVDsHhVqwLU2Ssbyeiq jxzTmv1e7itgQopeTi+5QHBnv1LAxpDpdXLH6kIAw4hLZ6snl+YlXyWfmk8UjZVXKoHA 86ypqzrOWS0R2EqF+sMtn4D6VcVLoGzJNjFwAngVj+xUDFxZkXgf3MuwvMJw1M8VcTUQ ICawjcq3OgzjkEhOrQrsfUaBPwUmbn1OMN1r8kJ1hbmt4Zvyo+8yZ1AoZwNvtkVD2Auy rhiZmGsM+PqIKkjIYAZbYHKavQZ2GTo/A7pxP1RFCZpIoL/R369BzhSI+aAPdkxHUAJd SElA== X-Gm-Message-State: ALoCoQmERhaS2iRchHK8Bi3G+esUN69BhkgcnetswJtZTlyChVKjvzYa9+US+1zDwkMCV8u35TTs+p/k4ZUEZBPZ0E+Du1oG/K5OP0WhcalUijbOoC3HEZKwzC4Ex3MFL1zdUNRra+Spei2fm73RKBun/Dj7x6RlwA== X-Received: by 10.220.87.203 with SMTP id x11mr689997vcl.58.1414016598890; Wed, 22 Oct 2014 15:23:18 -0700 (PDT) References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <866A39C7-6F11-408D-8BCA-594BA22E8569@ajf.me> <5447682B.2080100@sugarcrm.com> <019325A5-4F82-4179-B4D7-29E5649B2616@ajf.me> <54480580.9040302@sugarcrm.com> <4F848DB0-0266-46A0-9805-2B2BF22CAC33@ajf.me> <54480F68.6010406@sugarcrm.com> <058059C3-514C-4EA9-9468-3B9A8F20DCA8@ajf.me> <54482236.8030408@sugarcrm.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJkwG276Wk0Upx97kt7WiAQcULrfAGSwBqnAi5QI8QCGl+NrgJ4wNJWAjMdez4Cx9ORzgHpaYzMAtPTfXwCm2dukgGjAcZcAlYyDOSaTf+2cA== Date: Thu, 23 Oct 2014 01:23:17 +0300 Message-ID: To: Andrea Faulds , Stas Malyshev Cc: Dmitry Stogov , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: RE: [PHP-DEV] [RFC] Safe Casting Functions From: zeev@zend.com (Zeev Suraski) > -----Original Message----- > From: Andrea Faulds [mailto:ajf@ajf.me] > Sent: Thursday, October 23, 2014 12:42 AM > To: Stas Malyshev > Cc: Zeev Suraski; Dmitry Stogov; PHP Internals > Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions > > > > On 22 Oct 2014, at 22:31, Stas Malyshev > wrote: > > > > Hi! > > > >> Are you opposed to the existence of ext/filter given it has > >> FILTER_VALIDATE_INT, a =E2=80=9Cprimitive for handling type conversion= s=E2=80=9D? > > > > FILTER_VALIDATE_INT is an option for a filter_var function, and it is > > not introducing any new rules for handling types in the engine. > > Nor is this. > > > What you are proposing is not like FILTER_VALIDATE_INT, it's like (int)= . > > I don=E2=80=99t see the difference: > > $x =3D filter_var(FILTER_VALIDATE_INT, $foo); > > $x =3D to_int($foo); > > They=E2=80=99re very similar, except the latter has slightly different ru= les, is > shorter, > and if some people (possibly me) get their way, might throw an exception. Andrea, You're analyzing this from a purely technical perspective. There's a world of difference between these two if we take into account the human element. The former provides a very clear idea that you're in the context of filtering and validation. The whole point of filtering is to, well, filter out stuff. The latter, on the other hand, looks like 'PHP, please convert this to an int for me, the way you do these things, please.' I know what it does without looking at the docs. But actually, I'm wrong - it does something different, and has a behavior which is fundamentally inconsistent with the rest of the language that could easily result in broken apps. to_int() doing one thing, and (int) doing something completely different? That's a major #fail. If we use more explicit naming, this argument goes away completely. lossless_int() does a fairly good job at self-describing what it does, and completely prevents creating the false assumption that it's identical to PHP's type conversion rules. The chances the average developer would think that lossless_int() and (int) are identical is slim to non-existent. Regarding the fact that it's longer - I think we've made the decision to be explicit and not try to shorten things up a very long time ago (unfortunately not long *enough* ago). Clarity is a heck of a lot more important than a few extra chars. Not to mention that in order to properly use this new mechanism - people will have to write a lot of defensive error handling code around it - otherwise, what's the point. People who have a good reason to use these lossless conversions would not be deterred from 6 extra characters - even at the most minimalistic error handling scenario we're talking about dozens of extra characters compared to a simple (int) cast. Zeev