Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90516 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74402 invoked from network); 11 Jan 2016 19:47:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jan 2016 19:47:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain telia.com from 81.236.60.154 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.154 v-smtpout1.han.skanova.net Received: from [81.236.60.154] ([81.236.60.154:40103] helo=v-smtpout1.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/06-40147-ED604965 for ; Mon, 11 Jan 2016 14:47:43 -0500 Received: from [192.168.7.4] ([195.198.188.252]) by cmsmtp with SMTP id IiRGa7doXgj1IIiRGaSvtz; Mon, 11 Jan 2016 20:47:38 +0100 To: Giovanni Giacobbi References: Cc: PHP internals Message-ID: <569406DB.6080202@telia.com> Date: Mon, 11 Jan 2016 20:47:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfElHcnnR++ck/sG5lZ2KfxIkGImctrRtsdWl0hrscah2hrRc9I0HEBvaDrFZpGtlDay6h42rV2FOl5yqyyTghb77C3KucEOpu+DFddC62Vvi94SAUo7G nqS/mZDepgimI6Um62idODeE4vnnOdE7QKt3iaWjx7Tn+lJY7bAnzzPwi8q5VipRuBWVuTi5/g360SCDkrFP1ZSjJa16pf7KGwwxrMIsiTVeZWyhE5+zO8QL Subject: Re: [PHP-DEV] Throwable and Error exceptions break existing PHP 5.x code From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2016-01-11 kl. 14:31, skrev Giovanni Giacobbi: > Greetings, > > Short premise before I get flamed: I know PHP 7 is rolling and it is way > too late for this, that I should've tested the RCs, follow the mailing list > and so on, but I'm a dev like you guys and struggle with the time to do > everything by the book, including reading the previous threads because I'm > pretty sure this was brought up by somebody, but as there are hundreds of > message under the "Throwable" topic and I can't read all of them. > > In short I have this situation: > > class SpecificHandler { > public function exception(Exception $e) { > .. do something very useful... > } > } > > function global_handler($e) { > SpecificHandler::exception($e); > } > > set_exception_handler("global_handler"); > ?> > > This happens because the specific handler will output the exception > according to the expected format (HTML, JSON, or even an image). > > Now after upgrading to PHP7 when one of the new Error exception is thrown, > I get the following error: > > PHP Fatal error: Uncaught TypeError: Argument 1 passed to > SpecificHandler::exception() must be an instance of Exception, instance of > Error given, called in [...] > > Having been a PHP dev for 10 years now I know that the policy is to try to > break as little as possible while implementing new features, and I like > that. I know that sometimes things must be broken to progress, but in this > case maybe there is a very simple fix that I can suggest to avoid breaking > existing code, change set_handler_exception like this: > > set_exception_handler(callback function, bool also_throwables = false); > > The new parameter "also_throwables" defaults to false, so the same > behaviour as before is preserved. If you want it to catch also the new PHP7 > Error exceptions, you can just set it to true. > > What is your take on this? I know I can easily fix my code to work on both > PHP 5.x and PHP 7.x, but I really disliked this kind of BC. > > Kind regards > Giovanni Interesting idea, reminds me of the discussion in august, see: - http://marc.info/?l=php-internals&m=143980755928040 Then it was about if a set_throwable_handler should be introduced. Regards //Björn Larsson