Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44929 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10284 invoked from network); 10 Jul 2009 17:53:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jul 2009 17:53:07 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.117 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.117 us-mr1.zend.com Linux 2.4/2.6 Received: from [63.205.162.117] ([63.205.162.117:35487] helo=us-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/40-37812-100875A4 for ; Fri, 10 Jul 2009 13:53:07 -0400 Received: from us-gw1.zend.com (us-ex1.zend.net [192.168.16.5]) by us-mr1.zend.com (Postfix) with ESMTP id AE028E12BB; Fri, 10 Jul 2009 10:41:43 -0700 (PDT) Received: from [192.168.16.83] ([192.168.16.83]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 10 Jul 2009 10:53:45 -0700 Message-ID: <4A577FFE.5070705@zend.com> Date: Fri, 10 Jul 2009 10:53:02 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: John Coggeshall CC: PHP internals References: <7.0.1.0.2.20090708224156.0ac5a438@zend.com> <312025EF-84D0-4411-A0A7-4F0379C3105F@pooteeweet.org> <22CAD497EA2F476DAECEF9302D0B087A@pc> <98b8086f0907091150r47e7a103jaa50fcf7d5b32186@mail.gmail.com> <4A568B33.9000501@gmail.com> <98b8086f0907091744w7ab598dckc427d0a9484664b2@mail.gmail.com> <2B.30.23850.963965A4@pb1.pair.com> <1ae19b080907092002s7219220dg99b6d69d3b06f5ef@mail.gmail.com> In-Reply-To: <1ae19b080907092002s7219220dg99b6d69d3b06f5ef@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 10 Jul 2009 17:53:45.0352 (UTC) FILETIME=[5EA45080:01CA0187] Subject: Re: [PHP-DEV] Type hinting - Request for Discussion From: stas@zend.com (Stanislav Malyshev) Hi! > According to Zeev's description of the behavior this would cause a > fatal error, as $_GET['a'] cannot be converted to an integer value.. I > like that, but I think we need to devise a mechanism that allows you > to catch this error at runtime and write application logic around > it... In the simple case above the point would be to be able to catch Well, we could make it E_RECOVERABLE_ERROR. But it's not customizable, unfortunately. If you want graceful handling (like custom error messages), I don't believe you can do it language-level. Use app-level validators (like Zend_Validate in Zend Framework) for that. > the error so that the requesting user could be informed he must enter > two integer values. Off the top of my head the only mechanism that I > can think of would be to throw an exception, which I'm not crazy about > either: > > try > { > print foo($_GET['a'], $_GET['b']); > } catch(TypeCheckException $e) { > print "Sorry, you need to provide two integer values!"; > } If you're going to write specific code to catch specific exceptions, why don't you just check for specific constraints? It's the same amount of code, but done the right way - you say what you actually mean to do and do not make validation an afterthought, and allows you to give the user much better feedback ("this field is wrong" instead of "some field is wrong"). And what happens to your code after you add one more value? I think app-level validation mechanism would work much better in this case. > Personally I really like the practical feel and ease of understanding > of using an exception in this case, but the idea of an exception being > thrown from potentially procedural code isn't the best thing to me.. I think exception would be impractical in real user-facing code - it's too generic to give useful information, and you will have to have validation on top of that anyway (emails, html, whatever). -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com