Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75406 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48717 invoked from network); 13 Jul 2014 14:56:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 14:56:54 -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 192.64.116.207 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.207 imap2-2.ox.privateemail.com Received: from [192.64.116.207] ([192.64.116.207:33181] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/16-16748-53E92C35 for ; Sun, 13 Jul 2014 10:56:54 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 43C848C007B; Sun, 13 Jul 2014 10:56:51 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id kjyFpOiY6GBU; Sun, 13 Jul 2014 10:56:51 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 3CDBC8C0075; Sun, 13 Jul 2014 10:56:49 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Sun, 13 Jul 2014 15:56:46 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <9613A07D-D71F-4630-9AA6-5E47677B7281@ajf.me> References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <027E65EF-C4FC-474C-92BB-D99EFADDEEED@ajf.me> To: Zeev Suraski X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: ajf@ajf.me (Andrea Faulds) On 13 Jul 2014, at 15:41, Zeev Suraski wrote: > I don't think it's a common intentional case, but when writing code > defensively - you need to be prepared for whatever someone might = through > at you... Say I have a form that accepts 'age', and I expect users to > type in their age. As one that develops the backend, it's great if I = can > simply stick an 'int' in the function signature that deals with this > $_GET['age'], and know that whatever the user typed in - it would turn = it > to the most sane integer value. In other words, if someone types in = '12a' > (by mistake or intentionally), I think it's a very sane behavior to = just > treat it as 12, as opposed to forcing me (the developer) to write = error > handling code with a try/catch block, and a fairly hairy try/catch = block > too. Your example of "12 " (that I didn't even think about before) is = an > even a more likely scenario, but I think there's no strong reason not = to > allow both. I can see what you=92re getting at, but then I also think allowing =9312a=94= and the like could be a source of bugs. In this particular case, I=92d = probably explicitly cast the age myself before doing anything with it. Forbidding =9312a=94 is closer to the other type hints, which are = strict, but is also further away from zpp. I=92m a big conflicted. For now, I=92ll leave it as E_RECOVERABLE_ERROR. While user input might = be problematic, it can just be filtered. -- Andrea Faulds http://ajf.me/