Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113090 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43547 invoked from network); 5 Feb 2021 13:26:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Feb 2021 13:26:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66C2318050B for ; Fri, 5 Feb 2021 05:10:15 -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=-0.2 required=5.0 tests=BAYES_20,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-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 05:10:14 -0800 (PST) Received: by mail-ej1-f43.google.com with SMTP id w1so11794242ejf.11 for ; Fri, 05 Feb 2021 05:10:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=tIzX7ck96zWbSo10x6a8mCMifpBJFEvFKrzVQvwgzLI=; b=m0Qoe8dGwI6u5S0LCUEiodPqqPXC5WLzkl/G9Zvy1KhMRvCw7JIql0+ADFkFxVRDP8 /r++8tnx7JNQ6snoLXi/TFdOpOHWlsCBZCTj8HSkpvDZ14IQE77/43Zl19s7eYVHVp/3 YLkJU9v+jIaAEAOHzJ1lVDnuRm+nrgi2oHLZiUPBK1DCFYItbE7n1gBZjLjLDQaUHmdd RsO5FI02/QAdMO2fwsK/0rUFk8ITV9WgXpNs6+n3QL7iYGSkp6QPDX9baoB+P80DYIi4 b8snQ/xqkTKEZXtEmEShTgeywYCxE76rmj/1zd2DBlbQGlhkIoqP0KtsPqjr1J8qDIDr LyPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=tIzX7ck96zWbSo10x6a8mCMifpBJFEvFKrzVQvwgzLI=; b=UkatT/dvNrYl49/9F1oQt+KRk9m0Ubwza5HZQg2vjBQ97GzTUi7Wv9+yiQ9loSyffz ofVbsjl/sdJ5Ql7uo00BtspS5bz4xmMkdCiE8cD4hORiTTDIQn7FDbk5CdPnHGLgeIMO 3LKrSvaSqn1VcWFipflFi3fO/vA5wb2+2FLCP8Pk6SoDPzvl8kyCIGOXHD/u3aDyrNXz X3Bjd6Q8Ypf3Kq1ncftUPwqqFnyl/J50veHZjFOPsqiRSpdDLjvWphLKURT8Oq89+Tuq DaX/pwW6I6iRkVN5I4HGWSGaiQKwPXn0d2uvOqakCwJsXOPWC00X87KyhpSBjgBEHKEq 9ufg== X-Gm-Message-State: AOAM530/KYRQQm9CtlI2tn2H06oR9PKgCPY4ph0jz8Xrc7iUU85NEQeq Tbko7zyavtqNXRBAe4j7jCp4leRzm6v82HOU37GtcGyI3dAwuA== X-Google-Smtp-Source: ABdhPJzMo12cQlJ51nqk/WbDurjoYhpIm1QTv84zY47NeGHLSmmIFQs3XIRfpOYhF/7IfP/xWh9DEQGwkjN82ccdGmk= X-Received: by 2002:a17:906:b756:: with SMTP id fx22mr3851984ejb.406.1612530611948; Fri, 05 Feb 2021 05:10:11 -0800 (PST) MIME-Version: 1.0 Date: Fri, 5 Feb 2021 13:10:01 +0000 Message-ID: To: PHP internals Cc: Sara Golemon , Gabriel Caruso Content-Type: multipart/alternative; boundary="00000000000050916e05ba968a94" Subject: [PHP-DEV] Interaction between finally blocks and exit() From: george.banyard@gmail.com ("G. P. B.") --00000000000050916e05ba968a94 Content-Type: text/plain; charset="UTF-8" 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 --00000000000050916e05ba968a94--