Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60921 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59675 invoked from network); 21 Jun 2012 12:11:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2012 12:11:33 -0000 Authentication-Results: pb1.pair.com header.from=dmgx.michael@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmgx.michael@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: dmgx.michael@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:43249] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/43-42253-57F03EF4 for ; Thu, 21 Jun 2012 08:11:33 -0400 Received: by lbgc1 with SMTP id c1so2278021lbg.29 for ; Thu, 21 Jun 2012 05:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=RtdZWJ/6kYJj2Zfj4dVBy/nWw3BQIUttdHNNMH7EEIY=; b=pZjxtD59d1KHIfVhUpod10flpHtLLl/0EFAw48MZc0CMvdHoWnxLuhLkz4SswzP8Ai MsWfb9NKZ/UgE8LIzKcNPDoSvfb41xO6UZsrbGy4O5YGpNJtroVc6XcOVDKrWX9xekDH +it1KLTKl+NyPPcuGm1vpUpwZKMd28jxGo428hIQg22QNqoH/dxpT12dZdBy9+o8ROZ6 mhQuQ7lfz+Hpr/ZoTUwTYOQ4aA0480LWFRmv+JkcCT+b7LN3+DLr/7GVbe8MAl04zOqn cqHZR4o23AbgiEonr/rdV7v8+fV6LpfRyualY40AuLpEsRCDRtV2SgVRy6oFizvKgt3k le/g== MIME-Version: 1.0 Received: by 10.112.9.106 with SMTP id y10mr11471969lba.65.1340280690468; Thu, 21 Jun 2012 05:11:30 -0700 (PDT) Received: by 10.114.24.230 with HTTP; Thu, 21 Jun 2012 05:11:30 -0700 (PDT) In-Reply-To: References: Date: Thu, 21 Jun 2012 08:11:30 -0400 Message-ID: To: PHP Internals List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Resume keyword From: dmgx.michael@gmail.com (Michael Morris) On Thu, Jun 21, 2012 at 2:59 AM, Sebastian Krebs wrote: > 2012/6/20 Michael Morris > >> [/snip] >> >> An example for additional clarity. >> >> set_exception_handler(function ($e) { >> =A0echo $e->getMessage(); >> =A0// Don't know if this is correct - but should be able to illustrate h= ere >> =A0if ($e->getCode() =3D=3D E_NOTICE & E_STRICT) { >> =A0 =A0resume null; >> =A0} >> >> =A0echo 'Dying now'; exit; >> }); >> >> throw new Exception('A test', E_NOTICE); >> >> echo "We didn't die"; >> >> The code above when run would echo "A test. We didn't die."; >> >> >> > Whats about > > $user =3D $this->getUser(); // Throws exception > echo $user->getName(); > > > Now the second one will fail too, but in reality it shouldn't even get > executed... > > Regards, > Sebastian > > Then the error handler shouldn't have called resume. The error handler should only call the keyword if its safe to do so. And now that I think about it, not having the ability to return anything would be for the best since it would keep the usefulness of this to a minimum and avoid magic headaches. Cause the last thing we need is for people to start using the exception handling mechanism as additional control structure tree. What about what I'd mentioned before that this would allow? With this in place the existing PHP Errors could all be converted to Exceptions. The default exception handler would resume after catching any low level exceptions (E_NOTICE, E_WARNING, etc) but a custom one can be free to do whatever. Unifying the mechanisms also would allow for exceptions for other fatal events. This would be highly useful. try { require( 'path/to/file.php' ); } catch ( PARSE_EXCEPTION $e ) { // some logging then pretty death } Most of the time you'd never want to resume after such an exception.... Most of the time. In any event "resume" would allow PHP to get back to having only one exception mechanism instead of two since the behavior of errors could be emulated under exceptions. That is the principle boon of resume. Does that balance the two drawbacks 1) It's a new keyword, so BC breaks occur with code that used it as a function name. 2) The spaghetti possibilities increase.