Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8795 invoked from network); 11 Jan 2016 13:31:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jan 2016 13:31:22 -0000 Authentication-Results: pb1.pair.com header.from=giovanni.g@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=giovanni.g@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.41 as permitted sender) X-PHP-List-Original-Sender: giovanni.g@gmail.com X-Host-Fingerprint: 209.85.192.41 mail-qg0-f41.google.com Received: from [209.85.192.41] ([209.85.192.41:33172] helo=mail-qg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/A5-64385-9AEA3965 for ; Mon, 11 Jan 2016 08:31:21 -0500 Received: by mail-qg0-f41.google.com with SMTP id b35so272190668qge.0 for ; Mon, 11 Jan 2016 05:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Pq/M0gpZIf5R1VjCw1CZGgn+/FZlhcWb8sOtufM3tqM=; b=SBKvUqGtCp+eRCD0/Z9tcA5Ruf6uikrPHI1Ru8t8vCuZKpB5GfPlKOagF+m9GHTdDH O9mzfJ9bGwWZwyi6Ds2nY8N7TJ6oZKPSRkdY+SsyGlT+StMi4V/mRIF4vwJPAqPKS04M 3Q6xn/cRZ8nbLuOJ0stKIMmUj/csOC/N9nBnAbbedRpwycxEdgR2ro/cXVtRxbSdjclU 02JydMR4NSR9GMWPfryUS3Gohp0bQmVk/iYKI5qndQmDtagP+R2MXRDNbsbsnD+4xfAI Jm47KeFy2+IhMx4HFXg3HWBt1oJOAP64HH+7LMXQaTIvkE9qwaLY97T1VNXZJuNJ2vct gqEw== MIME-Version: 1.0 X-Received: by 10.140.106.228 with SMTP id e91mr161130332qgf.59.1452519078808; Mon, 11 Jan 2016 05:31:18 -0800 (PST) Received: by 10.140.41.148 with HTTP; Mon, 11 Jan 2016 05:31:18 -0800 (PST) Date: Mon, 11 Jan 2016 14:31:18 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a113a676cb8dc6f05290ef373 Subject: Throwable and Error exceptions break existing PHP 5.x code From: giovanni.g@gmail.com (Giovanni Giacobbi) --001a113a676cb8dc6f05290ef373 Content-Type: text/plain; charset=UTF-8 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: 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 --001a113a676cb8dc6f05290ef373--