Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107515 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37910 invoked from network); 11 Oct 2019 18:43:49 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 18:43:49 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 8477D2D2053 for ; Fri, 11 Oct 2019 09:27:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS21554 199.38.80.0/21 X-Spam-Virus: No Received: from mercury.negativeion.net (mercury.negativeion.net [199.38.81.6]) by php-smtp3.php.net (Postfix) with ESMTP for ; Fri, 11 Oct 2019 09:27:00 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 03D6F20775A477; Fri, 11 Oct 2019 12:27:00 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EUYNUsVhA9fW; Fri, 11 Oct 2019 12:26:58 -0400 (EDT) Received: from [10.0.1.2] (unknown [173.225.159.140]) by mercury.negativeion.net (Postfix) with ESMTPSA id 6F10020775A45C; Fri, 11 Oct 2019 12:26:58 -0400 (EDT) Message-ID: <36C65A63-3D5D-4EA4-A088-5E6B107F779E@trowski.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_5F098A3B-832A-45D4-A7A7-761B0353F8DF" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Fri, 11 Oct 2019 11:26:57 -0500 In-Reply-To: Cc: Marcio Almada , PHP internals To: Nikita Popov References: <2406F2E7-CD65-4E30-A98C-C09FB52B4F2B@trowski.com> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] exit() via exception From: aaron@trowski.com (Aaron Piotrowski) --Apple-Mail=_5F098A3B-832A-45D4-A7A7-761B0353F8DF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 11, 2019, at 10:21 AM, Nikita Popov > wrote: >=20 >> Hi! >>=20 >> So maybe it narrows down to: >>=20 >> Is there an essencial attempt to improve `exit()` handling from the >> userland perspective or should the focus be solely on solving the >> memory management issue pointed out in the beginning of the thread? >>=20 >> If the scope is to also improve userland, option 3 could be the way = to >> go indeed but I confess to do not be a fan of another callback >> registering thing... it feels hard to predict when you consider: >>=20 >> ``` >> catch_exit(function(){ >> exit(); // what happens here? We still have to guarantee `exit` to >> halt at some point. >> }); >> ``` >>=20 >> And what are the interactions with `register_shutdown_function`? I >> suppose the `catch_exit` stack has to be run before the >> `register_shutdown_function` stack? Considering the behavior in the >> docs. >>=20 >=20 > I think I was a bit unclear in how the catch_exit() function is = intended to > work: It's not an atexit handler, it's basically a try/catch block for > exits. >=20 > $exitExceptionOrNull =3D catch_exit(function() { > // Run code that may contain exit() here > }); >=20 > or possibly even more explicitly as: >=20 > catch_exit(function() { > // Run code that may contain exit() here > }, function($exitCode, $exitMessage) { > // This is called if an exit() occurred > }); The second option seems better, as it's a lot more obvious what code = will be executed if exit() is called and what will not be. Would a set_exit_handler function be possible, similar to = set_exception_handler? >=20 > I like option 4 much more for now. It allows tackling the root issue >> and still leaves possibilities open regarding how the exception >> hierarchy could be and how the handling of `exit` could happen >> (through a catch at userspace or callback registering). >>=20 >=20 > I guess we should do that as the first step in any case ... everything = else > would be extensions on top of that, but this would be the main = technical > groundwork. >=20 > Nikita Option 4 of course would be fine for now. Once that's done, we can = decide how exits could be "caught" in the future. > On Fri, Oct 11, 2019 at 5:13 PM Marcio Almada > wrote: >=20 >>>=20 >>> EngineShutdown could be a special exception to the engine, being = handled >> like an exception internally, but not implement Throwable and = therefore not >> an exception from user-land's point-of-view. >>>=20 >>> EngineShutdown could be added to the list of "throwables", but = forbid >> instigation in user-land. >>>=20 >> = https://github.com/php/php-src/blob/db233501ff9d56765ef4a870b777a643c21367= 11/Zend/zend_exceptions.c#L909-L916 = >>>=20 >>> No catch block would catch it, because it wouldn't implement = Throwable >> nor extend Exception or Error. >>>=20 >>=20 >> Very elegant solution! >>=20 >> PS: Naming things is hard, but `Throwable` could not have been a >> better choice in retrospect. Ty ;) Thanks! Every once-in-a-while I manage to name something correctly! >>=20 >>> Aaron Piotrowski >>>=20 >>=20 >> M=C3=A1rcio Aaron Piotrowski= --Apple-Mail=_5F098A3B-832A-45D4-A7A7-761B0353F8DF--