Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128351 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 C536D1A00BC for ; Thu, 31 Jul 2025 16:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753978985; bh=B5NMCcBJs0knyfnZkVmYkN65aVeJH+UbPHac7W6RiaI=; h=From:Subject:Date:References:To:In-Reply-To:From; b=nePwwSBqy8m+Bl6HgpLEha5FxZlAkX8bl0dZPl8HaTRN3NRe0C85dBIWqg1LIdySH uLZTTlwOryZik3zN+OUFQHlv5eROL9AUwR1oiPYcR4lMLba8uvL33mIFUe/FLePSxE GhruUkmLUZyu6C1Je0HPM9+g1wyC+aG56AYjix0OKQbBIExSCdyO0FuAJe8zSBgD60 esIBjvZMN3Ko7neXUk1AgqgkYsLF7z59GEMyuyej9bwEsyNBdrus94X+3Xtpgyrcnw EtgLSxeY0dcqMKwk7/NQLb4KCaRRbplTHOr4WmkL1OPYFr1NUnQ1y7UOdpP11w76Ig zvEGThZSFqVJw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0F063180086 for ; Thu, 31 Jul 2025 16:23:04 +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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, 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 mail.gna.ch (darkcity.gna.ch [84.234.28.114]) (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 16:23:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.gna.ch (Postfix) with ESMTP id BC0D02381826 for ; Thu, 31 Jul 2025 18:24:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1753979083; bh=B5NMCcBJs0knyfnZkVmYkN65aVeJH+UbPHac7W6RiaI=; h=From:Subject:Date:References:To:In-Reply-To; b=HSTbmQ7Y1KN6Ueq+SVc1wmAcxZPd3vkzUNPLQbTn6bm9KnTyAYJKFeYZCJrI4REox 1D5f49YTHPPJIzxd5A5ZDpoeFUMDfTmuydKToyeogyRxLsOIxtqqJrk5uwJP/D/3aY 4bzsSZ1YkS8vXpvXaxkGlvuzvzRoE/ZCBcUSaR/w= X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (mail.gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KSrWQj0eO8t8 for ; Thu, 31 Jul 2025 18:24:42 +0200 (CEST) Received: from smtpclient.apple (unknown [194.169.219.181]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.gna.ch (Postfix) with ESMTPSA id DDDF32381821 for ; Thu, 31 Jul 2025 18:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1753979082; bh=B5NMCcBJs0knyfnZkVmYkN65aVeJH+UbPHac7W6RiaI=; h=From:Subject:Date:References:To:In-Reply-To; b=VCI6lIiEkyYlsaJ1tvCjX5uKu1Bzkw13gVcqTYBvNXir2XNCWU/sV/n9MsD/cVhqx 0UTRIteMY3LxD7qiGuMaNkNnEo41N40cM9fnHdLYIwHW9ZthORjfTzAh7CtmrLh7Ks pWMkahSirHw/vy9NyAzXc+iIIUyQVIuss+nBzUv4= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body Date: Thu, 31 Jul 2025 18:24:42 +0200 References: <095f25f5-695b-46d4-9f31-5d7e7a04ce05@rwec.co.uk> <7E01A890-E986-4156-B598-ECD07264C39A@cschneid.com> <33e35f41-8d8d-4413-a36c-4cba4aa413a9@rwec.co.uk> To: internals@lists.php.net In-Reply-To: <33e35f41-8d8d-4413-a36c-4cba4aa413a9@rwec.co.uk> Message-ID: X-Mailer: Apple Mail (2.3826.700.81) From: cschneid@cschneid.com (Christian Schneider) Am 31.07.2025 um 17:53 schrieb Rowan Tommins [IMSoP] = : > On 31/07/2025 14:46, Christian Schneider wrote: >>> $fh =3D try fopen($filePath, 'w') ignore (FileLockedException); >>>=20 >> 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? >>=20 >=20 > 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 =3D @fopen($filePath, 'w'); > if ( $fh =3D=3D=3D false ) { > // probably something else had the lock; could also be an invalid = file path, or a catastrophic disk failure =C2=AF\_(=E3=83=84)_/=C2=AF > } If you have to handle null afterwards (e.g. avoiding writing to invalid = $fh) then the "ignore" version does not really help much IMHO Realistically I think it would be something like if ($fh =3D try fopen($filePath, 'w') ignore (FileLockedException)) { ... } [else ...] vs. currently try { $fh =3D try fopen($filePath, 'w'); ... } catch (FileLockedException) { [...] } which does not seem much clearer to me. > 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. ... so you would replace false for (some) errors by Exceptions, that's = what I meant. Plus having some stuff return false and some things throw = Exceptions seems weird too, that's why I said "all" in the first place. = But false/null vs. Exceptions is a different, much broader topic, let's = skip that for now ;-) Regards, - Chris