Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122483 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 36BBA1ACEBF for ; Sat, 24 Feb 2024 01:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708738699; bh=TbIyjigAnNxVS+8wnSSYh7NuhnaY8dnHn9onAG2YjzI=; h=Date:To:From:Subject:From; b=M6o7+4Ij5lERQD3HCmXSEcGII62FJwFPM9GX9GiLd24/dpDX47wvGn3O+dY37XdPy efE5cGZ0qirxEewaiklTLTOJBlkCfS8tpdH9YqCLP+bB+9/QNXboZNhry+Enklj6GS FQC+4zTzeIGOLRGhMUPdyf0CAn+k0LL4CTfa/Nu3aHx86v1WcOytzsdQDjmfMA0BAX KzJ4loGmpwUAL3B7FFOBQkuWRj/2IGwMDprHXKuSFPbsrNQhC5hs3EdAOeMeitadOg hU6oHIorejavy/sr69akKP+O4VwfZDzXKnJILC0aus6gdiz4TzJ98jf7ALMGgADBsR 1YucKNQfJl9ag== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F220718003E for ; Sat, 24 Feb 2024 01:38:16 +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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,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 mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Feb 2024 17:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail; t=1708738686; x=1708997886; bh=TbIyjigAnNxVS+8wnSSYh7NuhnaY8dnHn9onAG2YjzI=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=WJ9G/Q2vCKsBV56B80i7lAw/eNOfm71xAEHOJYHTHeVb6CN1rrKGCmbTKDTMNio46 cmP00frpSBYZsDv2Tzzm2Tc7bJ5TY3GRnnWgqUQFZAJePVL+5MLclJlOQgkCMc1Nzh dprcfijRvjLc2Uez4Yyy1XzB/I0pgK9GIvvpdJGOgCoBE7g1cEEm+NJofIDWJIyOY3 jxlAipanpW5fQQPhMwCuWnsKtEpA6ERHR5ZRZVlhoSQLunAyWiiNgSmghJUN9sQAdE GIb9lIhB3OcDepAZC0vlkPbKYWYYB0OCWsUSMcs+JuzO5phgO71/lRK4/QzTOu5mHu 9YgL/B07J/P4A== Date: Sat, 24 Feb 2024 01:37:51 +0000 To: PHP internals Subject: [PHP-DEV] [Pre-RFC] Convert exit (and die) from language constructs to functions Message-ID: Feedback-ID: 96993444:user:proton Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") 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 th= is 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 consta= nt 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 t= he disable_functions INI setting (the latter allowing us to define a custom gl= obal exit() which could be useful for testing that a function actually calls exi= t). We can also pass it like any other callable and reflect on it with reflecti= on. Finally, this removes the T_EXIT token and ZEND_EXIT opcode freeing one slo= t. 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