Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122484 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 720C71ACEBF for ; Sat, 24 Feb 2024 01:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708739913; bh=r0uVJOQnykqRU8/oWH6zW5iI7/ty1g6QYrjXSjcdRZ4=; h=Subject:To:References:From:Date:In-Reply-To:From; b=NFn34QcTI/k13BJCUJeTYn2z/0zWHMjWxz4kwQQNKTRmwyaz7lcLCyJpHpJY+EGNH UkBhLqlkt7ktrWcclhmGbeSSffvSTnNFXJrgaswaazekPr8+eNUGlO2RrID8JrhYu2 roPUxP6CHTZFjHUc1XgD3aHaQt0Ue8gRY96LWshELG6Lt5RrTUBr1RcVFPrpfG4+Ne ZQNnLsgXeUOp7MkNifOew20Mj71GE6fNfxW/WyG4wFNDak2I5rK/GM7g7/APaXLllY G7ZlIAeknYMf6ymVcOXNX7rK+DluZ72F7n2zKRmUSbXJ2Y2v+pq1DWtTthgR0z9Btg qiT+lYGoYz+9w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 096E7180079 for ; Sat, 24 Feb 2024 01:58:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_40, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from olivedrab.birch.relay.mailchannels.net (olivedrab.birch.relay.mailchannels.net [23.83.209.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Feb 2024 17:58:31 -0800 (PST) X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1376B4C1F1F for ; Sat, 24 Feb 2024 01:58:24 +0000 (UTC) Received: from nl1-ss105.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 5491B4C16E3 for ; Sat, 24 Feb 2024 01:58:22 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708739903; a=rsa-sha256; cv=none; b=iFoXqvILZHnWHs2e2ch23dTQr1MLUVQTNl+jJpMSBsiStTGi9Q+e+n6o3kn9qbls3bvmz8 IeGf8quXJ8NvhwcLPPgC+1wZae1hjmnfQyoS32wqnFqXhbzioGKkzpsfVhXvtM6Aa+6zR2 tHh27B41OLgZkDaJkxFiPeOl/SJE2NPjZu8esEAUivF4eiJCSOGjIOHW+k4ez/Zff/cAEE d8pxpXa0RAPmLA5L+kHZFFXzfsL0QFO+ZXJRx1kCDiaFbH+jVnzOb4PWgOjlNen7wdHqlr ZuKlkj9HMoslhBhCCQzfXS8ItFruw0jLxBo3qcr0wBkqTKWBe5D0/0gK94+1aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708739903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3+K55OEcJX3a4uNa2On/RXo1EFtxKstCRxONdpQYQaw=; b=AErDknLUUqRxkUTunByZRYzTj0OKaxxPeRIxmtl5vXds/VCPAWxCjmsq4lGBAn3r5cIdrC OLj3JHQ7xABGVw69Fy9rxut7IHkBJZsjKkCKm+yRkljhTgfZgVwffOHrVkgT2dEyZAAziN A2jH0Si7GKdHqT/w+47afyz+HlGsBqR2ARmES8VuSlzaIFg5xrb4ajiT7UzBvPKov1SM2w 9C5s86XaFEkyDT/vBnPmeRx0zbLgFbXpeHBbI3ujaSOlsLdhKzPaGoKNiaFBzmC5Fz6Ets LNWcQ1twEz1t+DVBRBU4GOlE/XYArZgtKbLMU9w81ASfrQB+IoHTkcGUL2cQsw== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-5lnkh; auth=pass smtp.auth=a2hosting smtp.mailfrom=php-internals_nospam@adviesenzo.nl X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|juliette@adviesenzo.nl X-MailChannels-Auth-Id: a2hosting X-Reign-Wiry: 04d069b70c3f8e2d_1708739903288_3952924302 X-MC-Loop-Signature: 1708739903288:4146217361 X-MC-Ingress-Time: 1708739903288 Received: from nl1-ss105.a2hosting.com (nl1-ss105.a2hosting.com [85.187.142.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.114.53.111 (trex/6.9.2); Sat, 24 Feb 2024 01:58:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=adviesenzo.nl; s=default; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3+K55OEcJX3a4uNa2On/RXo1EFtxKstCRxONdpQYQaw=; b=AWVLRi9u+a6UahrADgV5mCmvWD XfFJ+xTOuD1ygSQsGu+Oo3NrW9seNuv2f3U1pqlT9ytMCgFVyW30iaqZWpix2M6yBA0KKHcePCM+J vRoeTnOrxQzVICZOPcsBtGvIbIyfWncQAYZLzNdZY9bJjuuSTAGJ+oMUQ/jWtcGMp1tk=; Received: from mailnull by nl1-ss105.a2hosting.com with spam-scanner (Exim 4.96.2) (envelope-from ) id 1rdhIy-002Z2Z-1m for internals@lists.php.net; Sat, 24 Feb 2024 02:58:20 +0100 X-ImunifyEmail-Filter-Info: UkNWRF9WSUFfU01UUF9BVVRIIFJDVkRfVExTX0FMTCBWRVJJ TE9DS19 DQiBSQ1ZEX0NPVU5UX09ORSBCQVlFU19IQU0gTUlNRV9VTktOT1dOIE FSQ19OQSBNSURfUkhTX01BVENIX0ZST00gSUVfVkxfUEJMX0FDQ09VT lRfMDUgTUlNRV9UUkFDRSBJRV9WTF9QQkxfQUNDT1VOVF8yMCBGUk9N X0hBU19ETiBUT19ETl9OT05FIFJDUFRfQ09VTlRfT05FIElFX1ZMX1B CTF9BQ0NPVU5UXzAxIFRPX01BVENIX0VOVlJDUFRfQUxMIEZST01fRV FfRU5WRlJPTSBBU04= X-ImunifyEmail-Filter-Action: no action X-ImunifyEmail-Filter-Score: 0.18 X-ImunifyEmail-Filter-Version: 3.5.6/202401180837 Received: from [143.178.154.86] (port=49819 helo=[192.168.1.16]) by nl1-ss105.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1rdhIy-002Z2J-0y for internals@lists.php.net; Sat, 24 Feb 2024 02:58:20 +0100 Subject: Re: [PHP-DEV] [Pre-RFC] Convert exit (and die) from language constructs to functions To: internals@lists.php.net References: Message-ID: <65D94D20.6020702@adviesenzo.nl> Date: Sat, 24 Feb 2024 02:57:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------040606060709020302070008" X-AuthUser: juliette@adviesenzo.nl From: php-internals_nospam@adviesenzo.nl (Juliette Reinders Folmer) This is a multi-part message in MIME format. --------------040606060709020302070008 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 24-2-2024 2:37, Gina P. Banyard wrote: > Hello internals, > > I've been having this mild annoyance with exit()/die() since I wrote a CLI > script using a boolean $hasErrors variable to know if the script failed or not > and to indicate if the script failed via a non-zero status code by doing: > exit($hasErrors); > > However, it turns this doesn't work, because exit() will cast everything > that is not an integer to a string, something that I find surprising but > also weird as it will not type error on resources or array but rather print > the warning to the CLI. > > Anyway, yesterday I decided to put on my mad scientist lab coat and make this > a reality, I have a W.I.P. PR here: > https://github.com/php/php-src/pull/13483 > > I hear you, but what about exit; ?! > Do not worry exit; is still supported! > It only requires a _tiny_ bit of dark magic to achieve this! > exit; would just be interpreted as a fetch to a constant, > so when attempting to access the undefined exit/die case-insensitive constant > we just need to exit as if we were calling the function! > > Having exit and die be functions gives us access to some interesting > functionality, such as defining exit() in a namespace, or removing it via the > disable_functions INI setting (the latter allowing us to define a custom global > exit() which could be useful for testing that a function actually calls exit). > > We can also pass it like any other callable and reflect on it with reflection. > > Finally, this removes the T_EXIT token and ZEND_EXIT opcode freeing one slot. > > The W.I.P. PR implement every possible restriction: > - not being able to declare an exit()/die() function > - not being able to disable them > - not being able to define a constant named exit/die > > Maybe it would be wise to deprecate using exit as a statement to be able to get > rid of the undefined constant magic handling. > > Anyhoot, before I spend more time on this and write a proper RFC, do people > think this is a good idea or not? > > > Best regards, > > Gina P. Banyard > Hi Gina, I'm not sure a pet-peeve is a good motivation for creating an (I expect large) breaking change. The upgrade path, I suppose, would be updating calls to `die`/`exit` to always have parentheses ? Or alternatively changing those calls to new throw expressions ? While that shouldn't be that huge a problem for real codebases (and would be auto-fixable for adding the parentheses), the bigger problem I see is the huge amount of teaching materials, tutorials and blog posts using the versions without parentheses which will now all be invalidated. I think the pain and confusion that will cause for a change like this, will linger for years and years. Smile, Juliette --------------040606060709020302070008 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 24-2-2024 2:37, Gina P. Banyard wrote:
Hello internals,

I've been having this mild annoyance with exit()/die() since I wrote a CLI
script using a boolean $hasErrors variable to know if the script failed or not
and to indicate if the script failed via a non-zero status code by doing:
exit($hasErrors);

However, it turns this doesn't work, because exit() will cast everything
that is not an integer to a string, something that I find surprising but
also weird as it will not type error on resources or array but rather print
the warning to the CLI.

Anyway, yesterday I decided to put on my mad scientist lab coat and make this
a reality, I have a W.I.P. PR here:
https://github.com/php/php-src/pull/13483

I hear you, but what about exit; ?!
Do not worry exit; is still supported!
It only requires a _tiny_ bit of dark magic to achieve this!
exit; would just be interpreted as a fetch to a constant,
so when attempting to access the undefined exit/die case-insensitive constant
we just need to exit as if we were calling the function!

Having exit and die be functions gives us access to some interesting
functionality, such as defining exit() in a namespace, or removing it via the
disable_functions INI setting (the latter allowing us to define a custom global
exit() which could be useful for testing that a function actually calls exit).

We can also pass it like any other callable and reflect on it with reflection.

Finally, this removes the T_EXIT token and ZEND_EXIT opcode freeing one slot.

The W.I.P. PR implement every possible restriction:
 - not being able to declare an exit()/die() function
 - not being able to disable them
 - not being able to define a constant named exit/die

Maybe it would be wise to deprecate using exit as a statement to be able to get
rid of the undefined constant magic handling.

Anyhoot, before I spend more time on this and write a proper RFC, do people
think this is a good idea or not?


Best regards,

Gina P. Banyard


Hi Gina,

I'm not sure a pet-peeve is a good motivation for creating an (I expect large) breaking change.

The upgrade path, I suppose, would be updating calls to `die`/`exit` to always have parentheses ? Or alternatively changing those calls to new throw expressions ?

While that shouldn't be that huge a problem for real codebases (and would be auto-fixable for adding the parentheses), the bigger problem I see is the huge amount of teaching materials, tutorials and blog posts using the versions without parentheses which will now all be invalidated. I think the pain and confusion that will causeĀ  for a change like this, will linger for years and years.

Smile,
Juliette

--------------040606060709020302070008--