Re: [RFC] Optional Catch Block Body
| From: | Rowan Tommins [IMSoP] | Date: | Thu, 31 Jul 2025 11:16:09 +0000 |
| Subject: | Re: [RFC] Optional Catch Block Body | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128341@lists.php.net to get a copy of this message | ||
On 31/07/2025 09:31, Lynn wrote:
When I readAs I say, readability is always subjective, but I would just see ";" vs "{}" as a style choice, no obvious difference in intention. If anything, it would risk me misreading the code, because I'd be looking for the braces and not finding them. A similar argument was made for keeping "var" as an alias of "public", to indicate ... something; I argued against that reasoning at the time: https://externals.io/message/91618#91634 I don't think the language needs to allow multiple ways of writing everything, just so that projects can have subtle conventions of when to use which one.catch (Foo);I read the intention of it being on purpose, whereascatch (Foo) {}I can easily interpret as "the developer forgot to handle the error" or "I can't tell if this is a bug or not".
Now the boilerplate has increased from {} vs ; to quite some extra, just to ensure the intention. I don't know if omitting the body for this is the solution, or if there's something else we can do like: ignore(Foo, Bar). When I read the code I want the intention to be clear, and an empty body just makes me doubt whether or not it is intended and/or correct.
If the aim is to make the intention explicit, we need some syntax that makes the intention explicit, not just different punctuation we hope will become established as a convention.
$foo = try $this->doSomething() ignore (Foo, Bar);I think an inline syntax like this would be a powerful feature, and a potential replacement for the @ operator: $fh = null; $fh = try fopen($filePath, 'w') ignore (FileLockedException); One challenge would be optimising it so that the exception didn't build a full stack trace then immediately discard it - this was touched on in Larry's thread a while back https://externals.io/message/127188 -- Rowan Tommins [IMSoP]