Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59348 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67408 invoked from network); 4 Apr 2012 02:29:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2012 02:29:36 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.210.170 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:40257] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/09-06658-F02BB7F4 for ; Tue, 03 Apr 2012 22:29:36 -0400 Received: by iaeh11 with SMTP id h11so601565iae.29 for ; Tue, 03 Apr 2012 19:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=giXwKoV/LVV6ufn3Md02wJNkzP1rlBe3TWmEwJROIyY=; b=MYvO90QwynpTwkZ7S6pqTV20rNasA7D1NFaMcHc8g6kVZGyx9QO2hsVvsggE5vOx77 GMSulciBBaJLM/XkXo3QRt8d1kV/ujOLQqlSfaJT4c4006PoU/b0XT+10fIqBO8hWbZ9 x3711A0cBYGE5rOGNENGNLI5C0eqvE3tiCtxA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=giXwKoV/LVV6ufn3Md02wJNkzP1rlBe3TWmEwJROIyY=; b=WwZBuQqXoE2/li/xRhAAX4L5TRnScp/nFMQjUn2Wi01rtN/oc4IEHZZaASoxskYCm1 YHlgGjrd3cHgD9VoLLrHrvaDonGfbcnT4GbeGymoXFF25zu5NhMSW4k4latmEi1NjNvn rhC7C3Ep5xQi+yLE7wFRzHR7Jn/wFKaUIBPijwFmb9O/MWJgMhO3F0JkHZ2bIquFNM5y sQY4D8xccJb/UyiJykNUnm7KegflvOWsSzd9OdFEzBOvAwyFTFYCllNsnsDOcETJ3Z/I 2wVdSB6EoYjFcacHqf1nUVuIvfcEBLN6wSjeQKeJM3NnCSPut8/cB57SHe8gsmWQfqhi O8gw== Received: by 10.50.190.197 with SMTP id gs5mr236109igc.37.1333506573300; Tue, 03 Apr 2012 19:29:33 -0700 (PDT) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.42.243.73 with HTTP; Tue, 3 Apr 2012 19:29:12 -0700 (PDT) In-Reply-To: <4F7BABC8.7040904@akbkhome.com> References: <4F7BABC8.7040904@akbkhome.com> Date: Wed, 4 Apr 2012 10:29:12 +0800 X-Google-Sender-Auth: 2EhWd56JlMutm0amzntQTjKr7f0 Message-ID: To: Alan Knowles Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQk9FqNPZdjepJpWmcWKMFE5jSGEWOs3msLFS+BnODDkunPWOFd7HgW2r4yQPbluOqMHvE9a Subject: Re: [PHP-DEV] Catchable - marking methods just like static? From: aharvey@php.net (Adam Harvey) On 4 April 2012 10:02, Alan Knowles wrote: > PHP enforces rules like $this can not be used in a method marked 'static'= . > So why not flag methods (and internal functions) with a flag that indicat= es > they can throw things. Since PHP is not a compiled language we can not pi= ck > up 'all' of the potential scenarios, but even if E_NOTICE's pick up 80% i= t > would make code considerably more maintainable. I don't like this. It's basically the equivalent of Java's "throws Exception" antipattern[0] with none of the claimed benefits of checked, fine grained exception specification (which I'm dubious about in general, particularly having also used C++'s static exception specifiers, which are even worse than Java's dynamic ones). There are issues with both backward and forward compatibility here: assuming this was in PHP 5.5, you could effectively no longer write code that was E_STRICT/E_NOTICE clean in both PHP 5.4 and 5.5 =E2=80=94=C2= =A0you can't add catchable to functions in PHP 5.4 because it's not a keyword, but you can't throw an exception in PHP 5.5 without it unless you're prepared to incur a notice. And the associated performance loss, which may turn out to be significant if it's happening on most function calls in a script's lifetime. Also, I already know how to use exceptions, and write clean code. I don't really want to have to add catchable to all of the functions I've written that may throw =E2=80=94=C2=A0or may call library functions th= at may throw =E2=80=94=C2=A0when I upgrade to PHP 5.5. It's a lot of work, and giv= en that a lot of libraries now use exceptions, a lot of developers would end up almost mechanically adding catchable to pretty much every function, which loses any minimal code quality advantage that might exist. Exception specifications in general don't feel very PHPish to me, but that would be a different discussion. Catchable, as a limited form of exception specification, feels even less useful than that. > Anyway... flame away ;) Sorry, I guess I kind of did. It's nothing personal. :) Adam [0] http://today.java.net/article/2006/04/04/exception-handling-antipattern= s#throwingException