Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56573 invoked from network); 17 May 2015 13:10:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 May 2015 13:10:24 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:34489] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/12-32673-F3398555 for ; Sun, 17 May 2015 09:10:23 -0400 Received: by wguv19 with SMTP id v19so98437473wgu.1 for ; Sun, 17 May 2015 06:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to:cc :message-id; bh=0saWLZlkHvEBVQA0WfLzKaeoFrlg1hG6AD8RuGTtuaM=; b=DBYcY2LGk6Zm+5c0j6ggdaqMfuleB2u+jDmVS4MxtQ5fwJhWnmELhjGKtzPIAaE8WG rfkJkOnRf6+yUZNU/0ydBqpRcEcteCFpzZNXz6P25dhLuc48CkdZGwcqMgo4q1p1vSSa ZAhmjvBCsmrsGDfRAJEphdSmIargbZGq4MwJikRAPr0pZDhq0HisT2ahBCnFJnZVfM07 FqQ2dnSd1TxSwuhJU3ZXafOjvwIohvCErHsmQzEXR2zkhHI2rMtZEJlTEbTkvo5Lz5Lh 3tDAMddI5WEjOv+MqPSsoyjUrWmhsKRA6VfVvvu4d/5GfPN9dfFhMTlncs0rUL4FGhsB H9NA== X-Received: by 10.180.212.106 with SMTP id nj10mr13794898wic.53.1431868220004; Sun, 17 May 2015 06:10:20 -0700 (PDT) Received: from [192.168.0.6] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id mc20sm7549657wic.15.2015.05.17.06.10.18 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 17 May 2015 06:10:19 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <5541B4D6.9060503@php.net> <55425D7E.6010803@gmail.com> <554D8F4D.9020903@gmail.com> <554D90CC.3040607@php.net> <5552E3EB.5010800@gmail.com> <5552E494.5070401@php.net> <5552FF58.8070807@php.net> <55575DCF.50801@gmail.com> <55578C61.3040408@gmail.com> <555796C0.2020002@gmail.com> <5557A5C6.5050701@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Sun, 17 May 2015 14:10:08 +0100 To: Levi Morrison CC: internals Message-ID: <877A3955-C72C-4DB0-9B4D-E2891EE55095@gmail.com> Subject: Re: [PHP-DEV] [VOTE] Exceptions in the engine From: rowan.collins@gmail.com (Rowan Collins) On 17 May 2015 00:44:03 BST, Levi Morrison wrote: >On Sat, May 16, 2015 at 2:17 PM, Rowan Collins > wrote: >> On 16/05/2015 20:15, Levi Morrison wrote: >>> >>> The difference is that as time goes on and I've written code for PHP >7 >>> I was hit by this issue. It's an even bigger issue than even I >>> realized during voting. How many people who voted on that issue have >>> played with the code from both scenarios? Few, I can't guarantee it >>> but given the historical precedent it's almost certainly true. >> >> >> Can you give an example of the issue you were hit with? A sample >program / >> scenario, where failure to catch an EngineException caused behaviour >that >> was in some way worse than that under PHP 5? > >Here's a simplified example that illustrates one issue: > > >set_error_handler(function(){ > echo "Handled."; >}); > >function foo(callable $f) {} > >try { > foo("bar is not callable"); >} catch (Exception $e) { > echo "Caught."; >} > >echo "Done.", PHP_EOL; > >?> > >In PHP 5 this prints "Handled.Done". Under PHP 7 this fails with: > >> Fatal error: Argument 1 passed to foo() must be callable, string >given > >Note that if the TypeException had been caught by catch (Exception $e) >the program would have still been correct. This kind of setup exists >in PHPUnit for example; even if the test has some bad syntax or >failure the testing harness needs to continue. There are other valid >uses as well. An interesting example. However, the behaviour would still have changed if TypeException was a sub-class of Exception, because it would echo "caught" rather than "handled" (a trivial difference in this trivial example, but there's no reason to assume the actual code would be the same in both cases). The real problem here is that errors which were previously E_RECOVERABLE are now promoted to fatal when the exception is not caught. Unfortunately, I don't thick you can have both at once, because "recovering" an error returns control to wherever the error occurred, whereas an exception unwinds the stack looking for a matching catch block. So by the time an exception is flagged as uncaught, it's too late to make the error recoverable. Of course, many of the instances of EngineException were never recoverable errors in PHP 5 (a few more would have changed that way had EngineExceptions not been adopted, e.g. https://wiki.php.net/rfc/catchable-call-to-member-of-non-object). Whichever way the hierarchy is arranged, the ability of PHPUnit to handle errors is improved, not diminished; however, it may require a one word change, under the currently accepted proposal. Conversely, any code which handled E_RECOVERABLE but not exceptions, will now produce fatal errors, again regardless of the exception hierarchy implemented. It's certainly a tricky issue, and the vote was far from unanimous, but I'm still not convinced of the case to reopen it. Regards, -- Rowan Collins [IMSoP]