Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85620 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24496 invoked from network); 1 Apr 2015 02:18:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2015 02:18:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=neclimdul@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=neclimdul@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.44 as permitted sender) X-PHP-List-Original-Sender: neclimdul@gmail.com X-Host-Fingerprint: 209.85.220.44 mail-pa0-f44.google.com Received: from [209.85.220.44] ([209.85.220.44:36676] helo=mail-pa0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/66-19757-9555B155 for ; Tue, 31 Mar 2015 21:18:02 -0500 Received: by padcy3 with SMTP id cy3so37299140pad.3 for ; Tue, 31 Mar 2015 19:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=zKo4YTdiVk03BYr7BCrXcuwDqU7k1Jz+eI4Fjti/PEE=; b=HMsK8lOxzgWFIf+Qe5GNh82H1hV83D2QPZbkTPNvd6oqkJuEOU4B34bzv3JZ04H22d t9633wOQs6uSZXMPIA5UV5PMmTalJtziURuw9I6Pqgz8EnGHLfHJ00sJ9uWRk9HQe52Q Z0en6lva3yJPEg7CkuLvej/3bFCzBvOjgr8UwAsapYxtHRvIaasXChPAmtkRxp84GpuJ g8CdVAcf22uNHsrcL7IB1mTOlTriyWKBkpKbfFql4Z9seoapN2GbA3hBTeR1/yRHPX96 ZjraXuwAhIliGIJUvYPhOc+as35nZGVBDJ07GP+XmwYvkkNKCCI/vIh45+s0KeT4Wkjp rzbw== MIME-Version: 1.0 X-Received: by 10.68.90.132 with SMTP id bw4mr72403361pbb.102.1427854679131; Tue, 31 Mar 2015 19:17:59 -0700 (PDT) Received: by 10.70.131.3 with HTTP; Tue, 31 Mar 2015 19:17:59 -0700 (PDT) In-Reply-To: References: Date: Tue, 31 Mar 2015 21:17:59 -0500 Message-ID: To: Dan Ackroyd , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b675eb0f0ca620512a05214 Subject: Re: [PHP-DEV] Backwards compatibility with set_exception_handler callback and type hints From: neclimdul@gmail.com (James Gilliland) --047d7b675eb0f0ca620512a05214 Content-Type: text/plain; charset=UTF-8 That is a stellar response Dan, Thanks for being so clear. I had a feeling that this might be the case so we'll have to work around it. Just for clarity and posterity I provided the simplest test case in the original email not the actual problem. In Drupal this isn't just one place though becase, we have a library(and by library I mean class) for parsing information out of exceptions. So we would have to do quite a bit more hackery then that to to keep type hinting. On Tue, Mar 31, 2015 at 8:59 PM, Dan Ackroyd wrote: > Hi James, > > On 31 March 2015 at 21:51, James Gilliland wrote: > > By design, \EngineException does not extend \Exception so code doesn't > > accidentally catch this special type of exception. ... > > > > I don't know if this is all acceptable and/or by design but it is awkward > > so I wanted to bring it to the list to discuss. > > > Let me try to explain why the BC break at the top level is the right > choice. > > The change in the Exception hierarchy has to cause a BC break to exist > 'somewhere', as errors in code that were previously not throwing an > exception, but in effect just doing exit() are now throwing an > exception. This is a change in behaviour that cannot be handled > without some sort of BC break. > > There are two types of places where \Exception are currently being caught: > > i) in the middle of applications where some library is being called > where all exceptions need to be caught and changed to a more specific > exception. > > function foo() { > try { > someOtherLibrary(); > } > catch (\Exception $e) { > throw new OtherLibraryException( > $e->getMessage(), > $e->getCode, > $e > ); > } > } > > > ii) At the top level of the application where all exceptions are being > caught, so that they can be logged and a more graceful error message > than a stack trace can be shown to the user. > > If the BC break was for (i) by making all of the new exceptions be > under the hierarchy of \Exception, it would result in a lot of BC > break spread out across applications. > > Having the BC break in (ii) is pretty strongly preferable; it means > that there are just a few (or one), easy to find places in an > application where the code now needs to be changed from catching > \Exception to catching \BaseException (or whatever it will be after > the exception tidy up). > > Drupal (or any other application) can handle this BC break reasonably > easily by either dropping the type from the parameter of > _default_exception_handler or by adding a version check around it's > declaration like: > > if (PHP_VERSION_ID >= 700000) { > function _default_exception_handler(\BaseException $e) { > } > } > else { > function _default_exception_handler(\Exception $e) { > } > } > > Yeah, this isn't the most awesome thing ever to have to do, but imo it > sure beats having to change code in the middle of applications. > > cheers > Dan > --047d7b675eb0f0ca620512a05214--