Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94846 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59255 invoked from network); 5 Aug 2016 00:08:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2016 00:08:21 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.128.151 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.128.151 dd1730.kasserver.com Received: from [85.13.128.151] ([85.13.128.151:34285] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/64-33134-4F8D3A75 for ; Thu, 04 Aug 2016 20:08:20 -0400 Received: from dd1730.kasserver.com (dd0800.kasserver.com [85.13.143.204]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 998351A80123; Fri, 5 Aug 2016 02:08:17 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 138.201.158.68 User-Agent: ALL-INKL Webmail 2.11 To: internals@lists.php.net, bishop@php.net Message-ID: <20160805000817.998351A80123@dd1730.kasserver.com> Date: Fri, 5 Aug 2016 02:08:17 +0200 (CEST) Subject: Re: [PHP-DEV] Tracing exit() From: mails@thomasbley.de ("Thomas Bley") Hi! having a complete trace from an exception would be great: function shutdown() { $e = new Exception(); echo $e->getTraceAsString(); } function test() { exit; } register_shutdown_function('shutdown'); test(); gives: #0 [internal function]: shutdown() #1 {main} Regards Thomas Bishop Bettini wrote on 04.08.2016 20:10: > Hi! > > exit (and its doppelganger die) is a hard stop to the engine and there is > little telemetry provided about the circumstances (file, line, message, and > code). In source I control, exit is no big deal: I don't use exit! But in > library code, exit can be frustrating. > > register_shutdown_function + debug_backtrace doesn't help, because the > trace doesn't flow out of the shutdown function. xdebug helps to find the > exit frame, but cannot pinpoint the exact line. It seems like the engine > could help with a little extra telemetry. > > I'm wondering if the shutdown functions could access telemetry: > > register_shutdown_function(function () { > > $context = shutdown_get_context(); > > /** array ( 'exit' => array ('file' => '/path/to/Foo.php', 'line' => > 242, 'message' => "Calling exit() because...", 'code' => 0)) */ > // different SAPI may expand on this context > }); > > require 'vendor/autoload.php'; > \Vendor\Package\Class::callsExit(); > ?> > > Or, alternatively, I wonder if a method to convert an exit to an exception > would be better: > > echo ini_get('zend.exit_exception'); // "1" > > try { > require 'vendor/autoload.php'; > \Vendor\Package\Class::callsExit(); > } catch (\ExitException $ex) { // extends \RuntimeException > echo 'Stop that!'; > } > ?> > > (In all these examples, "callsExit" is vendor code that performs an > undesirable exit();) > > This latter approach feels more modern, at least from a user perspective, > but it has the side effect of making exit recoverable. IMO, that's a good > thing, because the conditions under which libraries exit may merely be > exceptional for consuming applications. > > However, I'm uncertain of an "exit exception" implementation. Perhaps when > INI enabled, zend_compile_exit could rewrite to emit ZEND_THROW with a > synthetic node. Or all the ZEND_EXIT could be updated to throw instead of > bailout. Don't know. > > TL;DR: Engine support for tracing/trapping/debugging exit helps developers > find and avoid hard exits in dependent code they don't control. Thoughts on > proceeding with an RFC? > > bishop >