Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129170 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 C218B1A00BC for ; Sun, 9 Nov 2025 17:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762708690; bh=27JCAEx1k4E7Y1/mc+Gma6kr11YYImt8myG4N/l2gSs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=REXgbGhpdiybOdU9LEu1rhK1TyQ+tYWPbMjuIsEQ66QljMwL4O+9whmIIfqu6kUrJ e232b2SYjeFN1XD3KCzAV1aaHdrsyI3W5/5txEIq7q80Ieu8C9E1B1T40sSaMUYEbG 4Uh6U1qpbnioYtEtb74i5DWnca3E9Hi5yu2QqNDgj13oPVjIlf7XpvLf9wV9KGb12S QgHeVe/0ILwPKApQ93C5qceJ3IMhjnsPl5s/0CvDpo/7D1ESPnAbnUKpQ/kVEzDTQS sCIjy7GRkr6SqrOGf5TwijIdaupPEs8qkOmkw9wWwElqF9w+2InZmk6L9XQ/27Ag5d mvhvPVWFKLu2w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 97059180055 for ; Sun, 9 Nov 2025 17:18:09 +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.6 required=5.0 tests=BAYES_50,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: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Sun, 9 Nov 2025 17:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1762708682; bh=NTby0kQHMhfOrYU2SyLjUFeElmJuBjv2rKBvh4zoqK8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=RcL2Bgivg0WRj9pW8iZyaENDyQMY0u/5Zb2TeKXSVrhfA7XhuGwijfrVfcQ34wgaR XUrr4TX/cuZNOR1hHIoA08h1+v1R+RzKbRj36amsu9anBEDgRTsL69wMcy0mv1+RgZ t/WNh4IcPohTG9+QqJQ4iOb0MlzTqPdj0CfwRb9/P2fljMorIrqnfCVU/mentOmpu9 PqcaD9tV2TowckjoVfsQrUFzC0eM1/GsRVf6NRCRsm4cj+KjuRMxzH5LlbUig0Vk39 T+qEtXTfsHq2XYo/m+88GBsYqzvkjfY5QvJsrkrvpvq00TY6vEwuOZxHUKXCSXL/39 VR9H8u+wDQNJg== Message-ID: <96013f5a-8ce0-4738-87e6-109706408faa@bastelstu.be> Date: Sun, 9 Nov 2025 18:18:01 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: Claude Pache , Edmond Dantes Cc: Seifeddine Gmati , internals@lists.php.net References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 11/7/25 20:36, Claude Pache wrote: > Indeed, and here is a proof (variation on the “Example showing reliable resource management” of the RFC): > > https://3v4l.org/KJaL1 > > Something like a `Disposable` interface as suggested in the Future scope section, is probably the only way to make it reliable, and it ought to be part of the RFC. It is correct that Exceptions will capture parameters, but I don't agree with the conclusion that this means that the “future scope” Disposable interface is a *necessity*. Exceptions will only capture the resource if it is passed to an external function. In that case, the external function is already capable of storing the resource somewhere else for future use. This means that the code passing the resource elsewhere must already be prepared that it might not close immediately. In fact the callee might rely on being able to hold onto the resource and it remaining valid. It would therefore be invalid for the caller to forcibly close it - as I had also mentioned in my (first) reply to Arnaud. The callee is also able to prevent the capturing of the lock in your example, by moving it into a non-parameter local variable. Like this (https://3v4l.org/tL5Yt): $local_lock = $lock; unset($lock); I'm not trying to say that this is obvious - I agree that Exceptions capturing parameters is something that folks need to learn about - , but it is a possible solution to this problem. Given that I don't agree that Disposable is the solution to the “Exception” issue, it's my responsibility to offer an alternative and I would like to do this: The addition of either an attribute or a marker interface for resource objects that the backtrace capturing will observe - similarly to the #[\SensitiveParameter] attribute. When an object is marked as a resource object, then it will be wrapped into a WeakReference when the backtrace is captured. As a result, the object will remain accessible for backtrace processing / logging as long as it would still be alive if there wasn't an Exception. But it will prevent the Exception from unexpectedly extending the lifetime in other cases. In addition I could imagine a WeakReference storing the class name of the originally stored object as a “poor man's generic”, allowing folks to learn which type of object was originally stored in the weak reference, even when the original object is already gone. Best regards Tim Düsterhus