Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86279 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1503 invoked from network); 16 May 2015 23:48:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 May 2015 23:48:10 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.169 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.213.169 mail-ig0-f169.google.com Received: from [209.85.213.169] ([209.85.213.169:36276] helo=mail-ig0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/82-14891-937D7555 for ; Sat, 16 May 2015 19:48:10 -0400 Received: by igbpi8 with SMTP id pi8so23644396igb.1 for ; Sat, 16 May 2015 16:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=YuM23EClU+APQx72F3ih4u6e1kq7mUuLl+/YEK/wFxQ=; b=TTRVIdpWcvwIDYMl2Kw4M/p4aaqMmztTrNCXYjpPbr91wQt1xAflGPOwxVuyDl76QQ zqNR4KvIWIyeenWnS+562kl9Bz+QCu3+JIV/sxbItdjMolftA/GFM3/gXckCu1mK2QQq wav2/8CV3D25ENzl/z7cME9bet8SLCAeUDG8sO1/0ibbpjCmUF224cm/i3u0T4w6e5/B DJgpyWOlxZdhs250FoNyLUniT4VF3QzJp/LBWstJDgaIkQfT96ryiudJabTNW40DrXP5 bOFVKPolbxUmnbzdVTLn9h6pZAwbX3xf6IWe4dhw7V3TNrxT1sDRMFb04OvZYiZzRpOT y5wg== MIME-Version: 1.0 X-Received: by 10.50.73.198 with SMTP id n6mr6468121igv.32.1431820087618; Sat, 16 May 2015 16:48:07 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.79.98.67 with HTTP; Sat, 16 May 2015 16:48:07 -0700 (PDT) In-Reply-To: References: <550DA4EE.2030903@php.net> <55410973.4010300@php.net> <55417C64.7000707@gmail.com> <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> Date: Sat, 16 May 2015 17:48:07 -0600 X-Google-Sender-Auth: 2Z19UTUhu__l332nlQSHuBswGUs Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [VOTE] Exceptions in the engine From: levim@php.net (Levi Morrison) On Sat, May 16, 2015 at 5:44 PM, 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. > > The only way to make this work in both PHP 5 and 7 is to modify the > code, despite the program being 100% correct under PHP 5 and the > documented semantics. To re-iterate now that I've shared an example: code is broken whether it's part of Exception or not. I would prefer to not break the code for people who purposefully utilized the semantics of error handlers and exceptions to write their valuable products. The people who didn't actually intended to catch all Exceptions should be the ones who feel the pain. It's also the principle of least astonishment: why isn't TypeException caught by `catch (Exception $e)`?