Re: [RFC] Transform exit() from a language construct into a standard function

From: Date: Mon, 27 May 2024 18:10:17 +0000
Subject: Re: [RFC] Transform exit() from a language construct into a standard function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-123438@lists.php.net to get a copy of this message
> Le 8 mai 2024 à 15:40, Gina P. Banyard <internals@gpb.moe> a écrit : > > Hello Internals, > > I would like to formally propose my idea for exit() as a function brought up to the list on > 2024-02-24 [1] with the following RFC: > https://wiki.php.net/rfc/exit-as-function > > There have been some slight tweaks to the implementation, namely that the transformation from a > "constant" to a function is done at compile time and we do not hook into the behaviour of > constants any longer. > > Let me know what you think. > > Best regards, > > Gina P. Banyard > > [1] https://externals.io/message/122483 Hi Gina, It is ok, for exit to be wired to a function. However, the paren-less exit syntax is absolutely reasonable and should be kept in the long term (more on this below). It is true that your proposal doesn’t remove the paren-less form, but the implementation (a hack around constant evaluation) strongly suggests that it is desirable to deprecate it in the future (hey, it is even the very first item of the Future scope section). Therefore, I think it is preferable to keep proper parsing rules for exit. Now here is why I think that exit syntax without parentheses is reasonable. For me, exit is a control-flow instruction, saying to terminate the program, just like return terminates a function or break terminates a loop. I don’t care about implementation details, whether it is implemented as invoking a never-returning function, or as throwing a hidden exception, or whatever. The fact is, in typical use: ```php header("Location: /somewhere/else.php"); exit; ``` I would consider an oddity and useless noise to put empty parentheses after a bare exit, just as I wouldn’t consider to put empty parentheses after a bare return. (BTW... I wouldn’t describe a bare yield (equivalent to yield null) as “constant” evaluation, even if it may be found in same positions as a “real” constant.) —Claude

« previous php.internals (#123438) next »