Re: [RFC] Optional Catch Block Body
| From: | Rowan Tommins [IMSoP] | Date: | Thu, 31 Jul 2025 18:16:48 +0000 |
| Subject: | Re: [RFC] Optional Catch Block Body | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128354@lists.php.net to get a copy of this message | ||
On 31/07/2025 17:24, Christian Schneider wrote:
If you have to handle null afterwards (e.g. avoiding writing to invalid $fh) then the "ignore" version does not really help much IMHOIn a simple case, yes, but you don't necessarily want the check directly under the fopen. Maybe you want to try opening multiple files, and succeed if at least one is unlocked; or try in a loop; or try in the constructor of an object, and handle it being null in a later method. It's still mostly syntax sugar (and maybe a hint to the compiler to optimise), but it's saving more than the original proposal, even skipping newlines: $fh=null; try { $fh = fopen($filePath, 'w'); } catch (FileLockedException) {} $fh = try fopen($filePath, 'w') ignore (FileLockedException); But, I'm not volunteering to write a formal proposal, let alone an implementation; I'm just exploring what kinds of short-hand might be useful. -- Rowan Tommins [IMSoP]