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 IMHO


In 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]

Reply via email to