Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130643 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 1ED181A00BC for ; Wed, 15 Apr 2026 16:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776271206; bh=XYnQodz3ya7qbUDoWOhN9HHjNN1vYZfbGrZxzFaqwHw=; h=Date:Subject:To:References:From:In-Reply-To:From; b=dhQqGXHSv1WChd/W/NU9Im3eCwVdMPLU2JavXdfx6nHH9xRPw9BXXHS+HqStxonNZ Kzh4SHtvBD0NIPBOk7qGt9s7BMFCZayDquexqeJnF6qbVP6yry3AFfp4GhE6TRJo6t s4F5SDRoWNj9sN/xyvVJWBAPxD2xL+moxETRkTzbZMAlsDEfALQSUtmvcQrJocxGfg i0oXLXuxNUWZ3LX3LqWbYUWjMd4pFlTl8tskuc3H7fmYWJN+RftEApeM347/ePf7r2 eAivH/jo4OqlRVnyVbfQpba7ojNL9yzZ6AAF07o7pDgjhGUkiImG5prir7iJTYUG31 tgSmd03imvGcg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9E4FD180078 for ; Wed, 15 Apr 2026 16:40:05 +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,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 ; Wed, 15 Apr 2026 16:40:05 +0000 (UTC) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-488a041eae5so52455035e9.1 for ; Wed, 15 Apr 2026 09:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776271199; x=1776875999; darn=lists.php.net; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=DEMZ97FqwNzU2FX0VPop1MCqwJj7TrDL41cG9PtenWI=; b=Mg+zLJZzVJu4pVZqtrUMgUeKsuLZGCB2ec0zbpGc4Vv1SgRR1A48Ei3n2KqtYiiLoq smtLU6sLBRtU4sGxdHaBTCd4/j7Km3LW0wWPE+89Rtf3Caq0Wbqpt1bfsXoOPObeKHWw AaRhgAZrth292iMqns7h1nfDXWvHYFkouCz+gTn6+/mCyJTMH4v+cEY5UvXP/8fOpuK/ rZ/369y16d2zW2yi00Ek3SvNFSBgrOr1Aa/F1QPQ7A+bxqTuhX8ABcyPoU1RsumEeEkx QBFRCXjsKAQl8DNTN2kWARfZO8qIurRUAzyXc99YzwEaGYkDCcRgTE+PeJvWLSwLtWNZ FaNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776271199; x=1776875999; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DEMZ97FqwNzU2FX0VPop1MCqwJj7TrDL41cG9PtenWI=; b=Iw1uYXKXvMxaszmIRlYnOtuZGNQcQqh3fss9DAJBj4RqIHnXvBsx4hbzRUjWnQBQHS puazWjh8TergQ7uq2OE9rQYl3RafwG3OoY6ZttPHtBqRdtrVNNqEdSNuJA7DOW7gskeK RaQ3Iuqf6SF9PdwTvUdvskr4dpPA/F1vf52PRx02gL72szvN0YDEEFf1KRZYRv2aWmhG Tr0cE+bJaRttuNJ4zQQSygK8tkuonHnMbFrF7fK71L9swuilz4ql5uUuwNQ+iv2lFlcJ L/ooJtrGDN60ChHvjkl8ZD5gOiOCEjwrx1OxVXrW/XH8Hx2AU4+P1P5LVDd4VNdy0kQk dBcA== X-Gm-Message-State: AOJu0YxR3G/HYsO2huz0/CVbDVH2o2m7kmiZjKRFb7/ttpR4K0c95pXd Z9t7B6bqDk2zRXs4FkiwoMuPJMgWO3fmuMi8PWCsUtuVhFlZev8dn7JrgWbdZMhx X-Gm-Gg: AeBDievlayRkXYhKKRTOw9Xqk/ppTzTDrglD1ifrc2CaLY2G0ZlkulMXGJQ7RqYl5V6 NcGaMujC9LkBBCVOeg799PUh/h8Yf52FFgiUxA22UR/wOit8+pp8YpPH6dxl6oIROV+Oi4lDKPc F3WqR+un9jiX00C8HsNSwWikA85PGDMJ5ABNQqf5kQnb3QABxBhnGjoDFNjVkkQ7d1D4jOkn/BC G1poSFAqmH0KGjM7AmvwCKTwwuA9n8lnz7Czryf8bY/DwCZfNtg1MELcpZmfEjYRkVYI+7FGSNS BtCbEQY6DerpGnNhIM4waOjgaxaEQW7t0l9t0AdWpW3VoublApNY8Bs3fYbSYShQu4RTZ1oQpOH df1XTBwfXBzDOxYiQ05r2odHLViEfdO+dUMfvIxacxxQEu9frwVNtNo4DiK6f4Nsfic7fcnsPXr LJSttTwITFpN5zkt4kEC1VLPoFiQaubbeVzxr5OBESqsme+IMdAt1XQqnW6AqQhXURkzuuBg== X-Received: by 2002:a05:600c:3b96:b0:488:b098:b653 with SMTP id 5b1f17b1804b1-488d67f0a8amr312514685e9.13.1776271198963; Wed, 15 Apr 2026 09:39:58 -0700 (PDT) Received: from ?IPV6:2a01:e0a:29f:2f50:75dc:7b3e:36b3:170d? ([2a01:e0a:29f:2f50:75dc:7b3e:36b3:170d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488f08b960esm40939805e9.0.2026.04.15.09.39.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2026 09:39:58 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------jBoTh6V2m03Bqyeouo0JGbPj" Message-ID: Date: Wed, 15 Apr 2026 18:39:57 +0200 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Language: fr To: internals@lists.php.net References: <5d96fca3ca5418e6e9e5d8871b26477f@bastelstu.be> <7991abf6-9cc8-444e-885c-4f8cd6078fa8@gmail.com> In-Reply-To: From: pierstoval@gmail.com (Alex Rock) This is a multi-part message in MIME format. --------------jBoTh6V2m03Bqyeouo0JGbPj Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 15/04/2026 à 17:10, Larry Garfield a écrit : > I think you're missing the point of this construct. What you're describing is much closer to the recently-declined `let` scoping keyword (https://wiki.php.net/rfc/optin_block_scoping). Yep, I would have been much more okay with a revised version of the `let` scoping keyword, though the implementation also seems quite complex too. > The entire point of context managers is to abstract away and make reusable the try-catch-finally logic. That logic needs to live somewhere so that it can be reused. That is what the ContextManager object is for. It's not a complication; it's the entire purpose of the RFC. > > Since you just recently joined the list you would have missed the earlier discussion in this thread of closures. (Seehttps://externals.io/message/129077). I have read a few of the messages on externals.io, maybe not everything, but your answer indeed makes things a bit clearer. It mostly makes me think that this RFC is a bit complex and I don't see /many/ userland use-cases that would actually need this. IMO, it tries to /make some safeguards/ implicit, like closing resources. I recognize that it's useful for this case, but does PHP really need a new feature this big "just" to close resources 10 milliseconds earlier in a process that takes 100ms anyway? The benefits would only go to projects with huge amount of concurrent calls, which are not all of them. > In short, closures are what people use today for this use case, but they're a PITA because they don't support auto-capture (unless you're using the single-line version). That makes them less common, because they're a pain to use in this case. In addition, they do create a new scope, which... is not what we want in this case. Not creating a new scope is a feature, not a bug. No auto-capture in closures is IMO an actual *good* thing, because it avoids having issues with the current world of JS/TS where auto-capture is default, and it brings problems with references. My suggestion with the `scoped` keyword also carries auto-capture by design, which makes the "capturing system" (shadowing, references, etc.) less intuitive in the first place. It's "yet another thing to keep in mind" at first, but for legacy apps renovators like me, it's mostly "they haven't kept this in mind" debugging hell ^^', but considering there's always worse, it's negligible, especially if it's intended to be a new feature. Still: creating a new scope makes things safer. It creates a new stack with its own pointers, and frees it at finish. They are a pain to use for now mostly because there's more code to write, it needs to be called (or auto-called with `()` after it), and capture must be explicit via `use` . The `scoped` keyword proposal automates all this with existing PHP features, while the ContextManager adds new features for that, and we don't know (yet) the overhead. Sorry for being this picky :) --------------jBoTh6V2m03Bqyeouo0JGbPj Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 15/04/2026 à 17:10, Larry Garfield a écrit :
I think you're missing the point of this construct.  What you're describing is much closer to the recently-declined `let` scoping keyword (https://wiki.php.net/rfc/optin_block_scoping).

Yep, I would have been much more okay with a revised version of the `let` scoping keyword, though the implementation also seems quite complex too.

The entire point of context managers is to abstract away and make reusable the try-catch-finally logic.  That logic needs to live somewhere so that it can be reused.  That is what the ContextManager object is for.  It's not a complication; it's the entire purpose of the RFC.

Since you just recently joined the list you would have missed the earlier discussion in this thread of closures.  (See https://externals.io/message/129077).  

I have read a few of the messages on externals.io, maybe not everything, but your answer indeed makes things a bit clearer. It mostly makes me think that this RFC is a bit complex and I don't see many userland use-cases that would actually need this.

IMO, it tries to make some safeguards implicit, like closing resources. I recognize that it's useful for this case, but does PHP really need a new feature this big "just" to close resources 10 milliseconds earlier in a process that takes 100ms anyway? The benefits would only go to projects with huge amount of concurrent calls, which are not all of them.


In short, closures are what people use today for this use case, but they're a PITA because they don't support auto-capture (unless you're using the single-line version).  That makes them less common, because they're a pain to use in this case.  In addition, they do create a new scope, which... is not what we want in this case.  Not creating a new scope is a feature, not a bug.  

No auto-capture in closures is IMO an actual good thing, because it avoids having issues with the current world of JS/TS where auto-capture is default, and it brings problems with references. My suggestion with the `scoped` keyword also carries auto-capture by design, which makes the "capturing system" (shadowing, references, etc.) less intuitive in the first place. It's "yet another thing to keep in mind" at first, but for legacy apps renovators like me, it's mostly "they haven't kept this in mind" debugging hell ^^', but considering there's always worse, it's negligible, especially if it's intended to be a new feature.

Still: creating a new scope makes things safer. It creates a new stack with its own pointers, and frees it at finish. They are a pain to use for now mostly because there's more code to write, it needs to be called (or auto-called with `()` after it), and capture must be explicit via `use` . The `scoped` keyword proposal automates all this with existing PHP features, while the ContextManager adds new features for that, and we don't know (yet) the overhead.


Sorry for being this picky :)

--------------jBoTh6V2m03Bqyeouo0JGbPj--