Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113095 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88093 invoked from network); 5 Feb 2021 23:57:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Feb 2021 23:57:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CAC68180506 for ; Fri, 5 Feb 2021 15:41:48 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 5 Feb 2021 15:41:48 -0800 (PST) Received: by mail-oi1-f173.google.com with SMTP id v193so3880136oie.8 for ; Fri, 05 Feb 2021 15:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b+IYlG22FTTNYpxmGVcG1j0KhHRF/FjTnyKJDjVfud4=; b=ai4RftLv1o2dD9LJY+yOCaoqOdCd5KYla6SIDLpwjwFEAfefb4KkGii1gK7TrTyXJO NjFgVP8EcnW5zxxFgfNzFNC3gVWpyiQucdJOAqXGkmkenbdY9MGn5mirfzKnXrsKFYE7 +Y7WND0JpmEN+6jLw5Q3cHx3TNm2+MCMdjJQgZ/0HhoP5E2YBBNq9v9OHbBgPs53E3Fg 3eiRG2Q8FhCuqHH7t6czGqWdDYeUyaUzkDt8xwtWPLqj28A/TZ/X6x16bWeFFmZHNo2X poKTf9dFPy9p69ougVYpG8Dmf7SCc/J/nLoeve3apED7BgC3V1glWvn49kSgnqM7TTJa k36Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b+IYlG22FTTNYpxmGVcG1j0KhHRF/FjTnyKJDjVfud4=; b=VYaj+KcEc1+zX/B11iHFCDTdtvNCa0Rh8oPsC0Bm4sikAxc807E63xxPoD0BUCqlWq JP7a2DsCMfTV5c+9dEbCyvA6oU3iHmT5XYgHc7Py+tEFzDnVm8gI1SxbBNArgHuqn0nq n0a5BduLbnOqE5cSmZ83dORaYjf0eQju8gr0bmJr7nD7/T6wZEKeBRSkTuHV1QTSmrXs feylukmPNV9wF3EcN1l0n99/5beBW3p8c8+f14rgf+z2p4psIsES3dK0MIcAYzEVYe8B 2bfFKkDljIq87JZlJ14EmE8otV/KPHPt/lbC1axpJZongn5mxqF7wDXLePc1N3dSJQf/ Xd6Q== X-Gm-Message-State: AOAM530uP3GkSYXdLvKT16806pjQx64eeLodvw1rZ9rnHifgx75/r85o ck6x3HbWA44Ob3DNrs/XE6XszBhKfy9QZgjMLwU= X-Google-Smtp-Source: ABdhPJzqP6vZ/ZIvzfRG+NiLZ2CFQRBqFZ70VHge6yZcut043UwIQmQsc9/7QKsG9ZlM1OuncWryck4O6H+60SlAqHM= X-Received: by 2002:a54:4185:: with SMTP id 5mr4604392oiy.7.1612568505222; Fri, 05 Feb 2021 15:41:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 5 Feb 2021 23:41:34 +0000 Message-ID: To: "G. P. B." Cc: PHP internals , Sara Golemon , Gabriel Caruso Content-Type: multipart/alternative; boundary="000000000000ee088805ba9f5c09" Subject: Re: [PHP-DEV] Interaction between finally blocks and exit() From: davidgebler@gmail.com (David Gebler) --000000000000ee088805ba9f5c09 Content-Type: text/plain; charset="UTF-8" Interesting. I'm not sure there's a "correct" answer here, but FWIW on balance my feeling is the expectation that exit() will immediately terminate a script (registered shutdown functions and destructors aside) should take precedence over the expectation that finally blocks will always execute, just because if you've got an exit/die inside a try block, I think it is reasonable to expect that you have already done anything that needs to be done before you get there (i.e. that your intent is for nothing else to happen), or to consider it a bug (certainly eyebrow raising code smell) otherwise. It's not the kind of use case finally was conceptually intended to address. And unlike an explicitly declared and self contained shutdown function or destructor, this could lead to what is effectively shutdown code being far removed and in a seemingly-random place in the code in relation to where the exit call occurs, maybe in a different file and not obvious to track down. Dave On Fri, Feb 5, 2021 at 1:10 PM G. P. B. wrote: > Greetings internals, > > While working on rewriting the PHP docs about errors and error handling [1] > I came across a change of behaviour in an edge case of an edge case. > > finally blocks are meant to be always executed regardless that an Exception > has been thrown or not, which it does, however a call to exit() (or die() > as they are aliases). > This can be seen with the following example: https://3v4l.org/6Tger > > However, there is one case where finally blocks are executed when exit() is > used, namely when a generator has a finally block and exit() is called > during its traversal, an example of this in action can be seen here: > https://3v4l.org/HGKHS > > The behaviour of this edge case of an edge case is highly dependent on the > version of PHP where this is run, PHP 5.5, 5.6, 7.0, early version of PHP > 7.1, PHP 7.2.0, PHP 7.2.1, and PHP 8.0 all run the finally block on exit(). > Later versions of PHP 7.1, 7.2.2 and above and PHP 7.3 and 7.4 all skip the > finally block. > > Frankly this is already going to be a mess to document, but this begs the > question is there a "bug" in executing the finally blocks in generators > during a call to exit() or is the "bug" to not execute finally blocks when > exit() is called. > > I've CCed the PHP 8.0 RMs as if the consensus is that skipping finally > blocks after a call to exit() is performed it would be wise to change this > behaviour in PHP 8.0 only and land this ASAP, even though it's a BC break. > > Interested in hearing your thoughts. > > Best regards, > > George P. Banyard > > [1] https://github.com/php/doc-en/pull/320 > --000000000000ee088805ba9f5c09--