Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107523 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69189 invoked from network); 11 Oct 2019 21:06:14 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 21:06:14 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 7B8B92CBF74 for ; Fri, 11 Oct 2019 11:49:25 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 11:49:24 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id c3so4869227plo.2 for ; Fri, 11 Oct 2019 11:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=gNQmw6nD4gZlLySVphupTVvxc35hPXbeauD8R99dovw=; b=Lo+ZaBWZ/nmMkGOTwZplHwq5/k57hVarBrmwVkSqvNYiklm7WsSSHjjT8WWQVk4T0F daMiK0zobuZFg62CVaLCCgCggh1T+27QQop1J+swfjNhyRsDIggHU7BnmPwJMlrsOdpi GgzWWmCjF07pNcplqpQgr2/yfiyEC7RdxarSkCsGYS1g7Y2prMK2J9nTdR/PC5QAIoI+ r74pgS4tLjiaAmGoreoc2b++KY5H/N2Kan1NFJySs0fpMAUcSFDmxL5rVvH8SVrGPStF H9Epr8sJU+2xhMDrnUXn60w1CSwrR+fAGNDkYJp5vkHkcCTIcL3n5x8dcHMPAr/cOZTG Wz8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=gNQmw6nD4gZlLySVphupTVvxc35hPXbeauD8R99dovw=; b=MeTDcgrbUOVb7y5NQvjoPzYWom/WeuiiHHiWldNOveQTWb9I1ltYEmkkTEmvG30mkw WWC50nhlTFPipVqvxoR9bAyf5sZboFtVF9gzuOrrMjoMWLJXt/6DxGQecu4YBz//noep GFLnSyRg4+GipUv6VITpdfli5XGzu8zVg15ixi2hzbhYBgXXwJ+dELE+IWDY4etPhFQu l92u7jbRIDTM+CNJ4XNXs7Kd/M/Pb4HRxkBL6FXAwR/eoyS35wyB0q80kv6bG1bLunYF qpcOD66pej99VRe455xZi1paNnvXHx7GASz7gmhRs40k8twgKGoaicCsF9jEhanwmxk3 +c4w== X-Gm-Message-State: APjAAAWbZ6tzzxJ9hNYI2eM5IlmrZgX2J+FyJq3N9Mj9Mj3NcFV86QWq VDF4SmDe7fGTXZKdtRijhdeT+ujS3w== X-Google-Smtp-Source: APXvYqywyV+NdWd2pkYzpIiq1t+SMBsNrpaawwKMJwUfYS9tcPrB5bH0n1J0ACozehTQOvASjmmLwA== X-Received: by 2002:a17:902:b60a:: with SMTP id b10mr17034680pls.130.1570819763106; Fri, 11 Oct 2019 11:49:23 -0700 (PDT) Received: from Stas-Mac.local (ec2-34-209-88-149.us-west-2.compute.amazonaws.com. [34.209.88.149]) by smtp.gmail.com with ESMTPSA id f185sm12961888pfb.183.2019.10.11.11.49.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Oct 2019 11:49:22 -0700 (PDT) To: Nikita Popov , PHP internals References: Autocrypt: addr=smalyshev@gmail.com; prefer-encrypt=mutual; keydata= xsJuBE9mqaARCACFSqcGmNunkjQQu3X+yXnTmFeEkvM4JXZTOBdR8aEevNGmmFEfyvjaDjWi 9hcwp4E/lYtC+P7VsVjM1OSX9eq0jC/lGL0ZyRXek+mNy0n5H1NSuTpf9Y18LMqhc4G+RU+L cNiZ9K0DJuOOvNLPxW7OHZguxb3wdKPXNVa2jyRfJAKm2uaJJMT1mTmFT9a0Q8SKr+mUrrJk uG0H2o6SzrKt8Wwoint1eh67zVsJaJtQFchnEZnlawIcqP2yC4nLGR3MkubowxoEBYCZet18 aHVVRbvpG2Qtob8Lu5xrsGbmXymTkHTdpvkfcJFADa8MzOL90zOxXwbGfbIZOlh5En8jAQCX lfnx2eQL3BSW/6XANa51dbWiEp1d1BAkpGKtZvlk0Qf+M9WAi+9aXMe3xP5krxtgnRNUf2WN 6Zdy2MxL1RRJCFbytLhl0ronC49BsGYVGshdEH8xhBbiIOJKuVZ/DTl9bEm7P9c7CC7iJyVC khUAhouH6xzZQNLR+RU+QebYzXypVfl99Qk7EdMmr/WAZCHLuvanyqepC5EBsa3VnAfQemSN oBeGBKWWLiOsPjvS72+y1z4RUMAfXHn4l/sFMt8zt7/74AmJPwZquV41p4mPO12V4+xPyc6R sB84sfsk2QVivU8w8AkvGQeYjXoz7Iwao95+fWteVzZ36KRQvUckP8pGjHlDXnHxJ0HI1I/k OBZSjwRwUf0dd73y6erPhbLk+gf+NdI3H9KGJBzG5/rVyWKwUeQ9d5ud4jTJRkQGvAP5pg76 vEa9dogbpe4W5Z+0BfbiJSnQmQWSHiZddj/t33ptbup44Ck6ZTgdlmFYMLF1hR47PIZTDKER EuKYGci/vq8snZvEJP9YCw/TtiHcMdrMKcY/+Lp8lQO0GHLPB9glVhnC0db6l1Xpg1CMI8/R ozBMcij30EgATggC/y2zbiqAFoS9FN9nXPbe4phSt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lWvF2gS126EQD/VVd3FgjLKglClRQP zdfU847tqDK4zJjbmRv5vLLwoE0A+wbrQs7jVGU3NrS0AIl5vUmewpp2BKzSkepy23nWmejw Message-ID: Date: Fri, 11 Oct 2019 11:49:21 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Envelope-From: Subject: Re: [PHP-DEV] exit() via exception From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > 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. Is that something that might be fixed in phpunit? I am not familiar with this specific issue but I'm not sure why unit test code can't use some other way to end whatever it's doing than exit() if that's the issue. Is it about the exit codes? If so, this probably can be fixed by other means? > 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. True, but that means exit() would become a) significantly slower b) may change semantics, which may or may not be a good thing. Also there's a possibility of exit() failing then which is not something we've had before. > 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 don't think this is a particularly good idea - first of all, using exception for flow control is wrong. Second of all, if you _want_ to use exceptions for flow control, you already can. If the code uses exit(), it usually means exit, as in drop everything and get the heck out. It may not expect that lots of code will run after that (yes, I know, shutdown handlers, but they have to be clearly installed as such) that may still do a lot of stuff - while the state of the app is potentially broken. If we make exit catchable, then the next request would be to implement real, un-catchable, exit that actually implements the old semantics. Sometimes people don't care about memory leaks checking but want to just abandon the boat and let the memory manager to clean up the mess (or even not that, just kill the process and be done). > 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: I don't think it should be Throwable, since you a) can't and shouldn't actually throw it and b) code that catches Throwable does not expect to catch exits, so it would break its semantics. Granted, there's almost never is the reason to catch Throwable, but if you already do, you'd be in for a nasty surprise. > 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. If you want to do weird things - like have exception that it's really not an exception - you'd have weird hierarchy. Either that, or you make existing hierarchy weird, which existing code (and virtually everybody writing new code) does not expect. I think theoretical weirdness is better than nasty surprise for the practical users - which would either have to insert instanceof checks into their catches, or deal with exit() behaving wrongly. -- Stas Malyshev smalyshev@gmail.com