Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107499 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71260 invoked from network); 11 Oct 2019 14:00:14 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 14:00:14 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id F006A2D203B for ; Fri, 11 Oct 2019 04:43:22 -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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 11 Oct 2019 04:43:22 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id 4so8556301qki.6 for ; Fri, 11 Oct 2019 04:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FjsfUcXdQc6MTvuLSRho3eBCbfQeyMGGauYsNL/ug0o=; b=0IguyjlHlZ65RLhnZz3T+PD4vfR+EWMtkBqGGKMGDNk9IDId+1DdTuIKXlR/OekX0u ub/Y1cVKRqvOYzobjVv4DYI+7t47e6o5rXwd97kIjDwS3Y8wOsXaahJ6FMrGOt8xn9TZ iJTHS+4E3HABx3DhTTOtGMPbS1bElwoshEN2MaRa67MMX8FVwqZmNpJIX2exdGlRL0Op Y1O2GTmVYW7TuCeGN33AEJkUAUQP265McFK9tQSHejVhmu8jwQiRKLbRXfF1n0DaEPNV fQVKAKbeUZdTodFUvGyAzlnIFSbX/ZhDXCEv0Ahm5BqXbU6rCMtvo/k+Lunn1aEq9HkK /SSA== 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=FjsfUcXdQc6MTvuLSRho3eBCbfQeyMGGauYsNL/ug0o=; b=ph6SscFszwMKaumF+NlP2Xs8u0vyHR3ZdGiXJrdAKJPUydFEea0d8SzFQAzRacsGCE b47KF8cSt/zqmetVkWXGBlMPcxiAFMI/PkalL9sbtGG8iXP0DXDGDR767jRxn0hOPw5f xmUWasx51LdkdbLHFC3AjuVmB+N2/cBpSD0TIxWjusOvG//0qJtw/G0hP2i+Eh+1uxC4 2xvLwLjIznRsClyFG+QZnjDwUU1wrGA3k39Rr123q+BBDkov5DZclNrlDIlQ+2zvwgO0 lc68lQL2xsOU/98X1nrX+/jWfpShfOmE2CxlTpbRCf5s2IxCynRGS0muTlkF4c8EMkXR nMuw== X-Gm-Message-State: APjAAAVUnDiQCOKUTDjHl/A2M0IQQ4Qvqx00yg22ukid8v2IZbkk71Ef AobcvAMq1+9KokX81xN5nyFEWJbon0g= X-Google-Smtp-Source: APXvYqzS3uoVbM9R+zW2c3WNdZ3lCK4OP1nPHhslB9iIJUPeOWDWX+/CvM9YaV9dLafD3Y0BZ25Bdw== X-Received: by 2002:a05:620a:2111:: with SMTP id l17mr15200842qkl.74.1570794201676; Fri, 11 Oct 2019 04:43:21 -0700 (PDT) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com. [209.85.160.180]) by smtp.googlemail.com with ESMTPSA id i66sm3932714qkb.105.2019.10.11.04.43.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Oct 2019 04:43:20 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id o12so13417527qtf.3 for ; Fri, 11 Oct 2019 04:43:20 -0700 (PDT) X-Received: by 2002:ac8:47c7:: with SMTP id d7mr16656682qtr.29.1570794200077; Fri, 11 Oct 2019 04:43:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 11 Oct 2019 13:43:09 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] exit() via exception From: andreas@dqxtech.net (Andreas Hennings) I would think that whichever code currently calls exit() is already expecting and accepting all the consequences, and assumes that this won't ever be caught. So, would it be an option to keep exit() as it is, and introduce a new syntax construction? Places where I have seen exit() were not really about exceptional emergency situations, but rather a "finished" or "done". E.g. "send headers, print ajax response, exit". This may or may not be good practice, but it is something being done. What other use cases exist for exit()? > introducing *yet another* super-class/interface above Throwable, which is something I'd rather avoid. I don't see a way to avoid it .. But if we are going to do this, we should think about whether we really covered all cases, or if we need another layer in the future. interface Throwable extends Catchable {} On Fri, 11 Oct 2019 at 13:05, Nikita Popov wrote: > > Hi, > > Currently exit() is implemented using bailout and unclean shutdown, which > means that we're going to perform a longjmp back to the top-level scope and > let the memory manager clean up all the memory it knows about. Anything not > allocated using ZMM is going to leak persistently. > > For me, one of the most annoying things about this is that we can't perform > proper leak checks on code using PhpUnit, because it will always exit() at > the end, which will result in "expected" memory leaks. > > I think it would be good to switch exit() to work by throwing a magic > exception, similar to what Python does. This would allow us to properly > unwind the stack, executing finally blocks (which are currently skipped) > and perform a clean engine shutdown. > > Depending on the implementation, we could also allow code to actually catch > this exception, which may be useful for testing scenarios, as well as > long-running daemons. > > I'm mainly wondering how exactly we'd go about integrating this in the > existing exception hierarchy. Assuming that it is desirable to allow people > to actually catch this exception, my first thought would be along these > lines: > > Throwable (convert to abstract class) > \-> Exception > \-> Error > \-> ExitThrowable > > This does mean though that existing code using catch(Throwable) is going to > catch exit()s as well. This can be avoided by introducing *yet another* > super-class/interface above Throwable, which is something I'd rather avoid. > > Anyone have thoughts on this matter? > > Nikita