Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85619 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22392 invoked from network); 1 Apr 2015 01:59:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2015 01:59:43 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.215.45 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.215.45 mail-la0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:35003] helo=mail-la0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/06-19757-E015B155 for ; Tue, 31 Mar 2015 20:59:43 -0500 Received: by lahf3 with SMTP id f3so25572968lah.2 for ; Tue, 31 Mar 2015 18:59:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=T7z4JphKz1C5FfKBTmHUlHimP5Ew6H1axitXrj+VGsY=; b=dez+wZzc3y+WEsqKWYxOjhrhrP9XZ1N1gnzJuseXGPJm+D73E6gY6KTK21LQd5PmFR mOWxbryptPEGJ5t4DAH2J+7n6g4uldjURae39hCNUN1iA4PUuN2WqZQiNYap4O7gpGtD CMBTvzdsJiO46BD7u0T9Wq0z7PUhsAQO2PqLMEw2Fk7rfZ2LeZhdUmRSiLIyejMbfc98 wsMUPboyX9i+PW13jdcIf7awwxs4StuD+ppyUChajus2e7bbLk3oBqZ6mGRCliG5QAwC DMLN3biPyIYleSMoEDO9MH1dui2YnirVQayZvn2YNOV9yEp8Dyfj8dcwwbzqohTGDWjX Y0Lg== X-Gm-Message-State: ALoCoQniPKHZAH9Ojz8GRt/tTeR/hVVobtCso8KJrv4AEAuEMK9XKYeeulZY/kogFw5L3JpYtkD9 MIME-Version: 1.0 X-Received: by 10.112.131.66 with SMTP id ok2mr33103606lbb.51.1427853580087; Tue, 31 Mar 2015 18:59:40 -0700 (PDT) Received: by 10.25.87.202 with HTTP; Tue, 31 Mar 2015 18:59:40 -0700 (PDT) X-Originating-IP: [78.144.121.114] In-Reply-To: References: Date: Wed, 1 Apr 2015 01:59:40 +0000 Message-ID: To: James Gilliland Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Backwards compatibility with set_exception_handler callback and type hints From: danack@basereality.com (Dan Ackroyd) 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