Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128349 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 lists.php.net (Postfix) with ESMTPS id 3C3E91A00BC for ; Thu, 31 Jul 2025 15:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753977092; bh=BcApkDRAO4SW52FDtgUOoDN2JmkUXWwKTjl2BKmGpmI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Znxjldc5n1/emTKJIr1Dhg+nGfI8noFcNTp9GrlRi+3pjyiP9IUrhfRQ/8SlrkxDR 9fCTtGwfU2owMjdkJe2kPY7AvjrW/gOBIZ6MHR2q8RaX4vvoRMNItOYTP51mmG1DKu FsrjkOaEFk775pss1flZ3Cb/MYxSY/l7Zmlcp4VBmgz3Yr6MbrV4DD8vmsrBQMIVxY bF6wP+NBAx16ciqjF0AEB9okdLKlfiiBcDvRty4t2Y9l4kXcgpQA+2ZKW9kLSEo0Pc DdORxXQWIpQ+A4Ep8GcPgcg5XdUnuolYHS+zBRIvXR1COHigaAnPwD8cp40K3IqLen KDDXTyrihq6IA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A03618006C for ; Thu, 31 Jul 2025 15:51:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) (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 ; Thu, 31 Jul 2025 15:51:31 +0000 (UTC) Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4AAD77A20C7 for ; Thu, 31 Jul 2025 11:53:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Thu, 31 Jul 2025 11:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1753977193; x=1754063593; bh=K97rdfdb0B e/si5w/r8ESCbYkE9dDnf7CCqMD5Sah48=; b=DIbKheoZggpPfnUyjdKwwOjWX4 WOldeK41xDj+yzOD3T/3wUbbdFvXSoS804i7Wm1ofU4mzccjTDh/nRZF8/r+bdwp YATEoepqIx4GEozh3f7caYxxJgoFlMXIZAsX4/3k3rJAo+detpoVCLY3mTyRcuua /EixQrJKgXnkXxT5Jg50F9dfIo/tbnFMcDv/ZGy3GlDDfu0hzObUfancnewybF1d WIiAxFxJEeGxaMMe2uRk0D4zNNOFv0kZdLm3cYnrNKsc1AUQs2lsVLbv4ZHPlQ2p 3eolpBnEPuHe1+AP/2tolK81d+RFdzgM30JbKOOWk94QiWopUfwewAkRKjeA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1753977193; x=1754063593; bh=K97rdfdb0Be/si5w/r8ESCbYkE9dDnf7CCq MD5Sah48=; b=iUT3LnB84xWgO2oNGd4Na0iXkIsinHCfhjoGYLl4aLVTXNGAeUY KNIXG5uFX384oXogKWi7Hof3BGhC3RQZ9oyWa6OgDA8fKxjuFql0KPF7DaJHIELJ f7fKxybvWIRgpSCkoG8gwHxWlBGVPY+7YmtC/UCYskjI5zdKVJRulPHnpaInho+i gQU1YBfSXHyujrxMhZJhdtimiv+jkGLb6bA+N1qZOEIVGhBrghGLw/jCKuburzkW nJeUXPUv2yOlnGAun3R6jEKlTuG8p3ziJNMud8Kc1iI+a4/vJEOq+QeH2LpYmL9K YIzS+F7x5KxAO7j3R9g3FRWgo4S2XcHcARQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdduvddvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtreertd dvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehi mhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepheetle eiiefgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhph esrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 31 Jul 2025 11:53:12 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------wt5IeCCUakya6GINMectBPv9" Message-ID: <33e35f41-8d8d-4413-a36c-4cba4aa413a9@rwec.co.uk> Date: Thu, 31 Jul 2025 16:53:10 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body Content-Language: en-GB To: internals@lists.php.net References: <095f25f5-695b-46d4-9f31-5d7e7a04ce05@rwec.co.uk> <7E01A890-E986-4156-B598-ECD07264C39A@cschneid.com> In-Reply-To: <7E01A890-E986-4156-B598-ECD07264C39A@cschneid.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------wt5IeCCUakya6GINMectBPv9 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 31/07/2025 14:46, Christian Schneider wrote: >> $fh = try fopen($filePath, 'w') ignore (FileLockedException); > First of all: I'm wary because partial error handling seems dangerous to mel do I know all possible Exception types and which ones should abort and which ones should continue? That's kind of the point: it's for when you know how to handle some specific cases, but want *anything else* to abort. In this hypothetical example, the code is using an exclusive lock to avoid two processes writing to the file; it wants to gracefully handle the specific scenario of "some other process has the lock". If there's some other error, like "invalid file path", that *should not* be suppressed. But the current PHP I/O functions give no way to distinguish: $fh = @fopen($filePath, 'w'); if ( $fh === false ) {     // probably something else had the lock; could also be an invalid file path, or a catastrophic disk failure ¯\_(ツ)_/¯ } > I have to admit that I'm also a sceptic of converting every possible info/warning/error to an Exception but that's a different topic I didn't intend to imply that this would replace all Warnings. Think of it more as replacing the "returns false on error" part of the fopen() signature. > If we decide to add something like the above I would very much prefer the try ... ignore block to be an expression with value null on error, making the first line obsolete. Good point, I agree. -- Rowan Tommins [IMSoP] --------------wt5IeCCUakya6GINMectBPv9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 31/07/2025 14:46, Christian Schneider wrote:
$fh = try fopen($filePath, 'w') ignore (FileLockedException);
First of all: I'm wary because partial error handling seems dangerous to mel do I know all possible Exception types and which ones should abort and which ones should continue?


That's kind of the point: it's for when you know how to handle some specific cases, but want *anything else* to abort.

In this hypothetical example, the code is using an exclusive lock to avoid two processes writing to the file; it wants to gracefully handle the specific scenario of "some other process has the lock". If there's some other error, like "invalid file path", that *should not* be suppressed.

But the current PHP I/O functions give no way to distinguish:

$fh = @fopen($filePath, 'w');
if ( $fh === false ) {
    // probably something else had the lock; could also be an invalid file path, or a catastrophic disk failure ¯\_(ツ)_/¯
}


I have to admit that I'm also a sceptic of converting every possible info/warning/error to an Exception but that's a different topic


I didn't intend to imply that this would replace all Warnings. Think of it more as replacing the "returns false on error" part of the fopen() signature.


If we decide to add something like the above I would very much prefer the try ... ignore block to be an expression with value null on error, making the first line obsolete.


Good point, I agree.


-- 
Rowan Tommins
[IMSoP]
--------------wt5IeCCUakya6GINMectBPv9--