Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130794 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 74C3B1A00BC for ; Thu, 7 May 2026 15:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1778167151; bh=QLkTo/EJMyFlQbdPZjSTVSQl64SJ/skNuD3epTAye7Q=; h=Date:Subject:To:References:From:In-Reply-To:From; b=YQZBg8e+4H55rxE57QU5sNWQjz8N3hZtjJZILQV7/O+qX33DGxF/pAbA7k9VL0fWs uV7oNCuaImW5iAzS6X6cxXEj0aHb0qmBg5YszRiB0NCjUjrE4NJgP+ie4BpmUnea9I AnZBjOuTvunJjLqVXKEvuJ81gP3aNMEpHf4x6bmCVVWS9l8Qmzq24KhmU7TXUq9EFP LHImAGpdnT7VjuA1l43NB5FP8XHrsERyAlDofV6RmQHu4uFOhs/aaA/23Yle2yM5cw eE//GTE7GL9mOJNnyREP5WKeow6wugGJUHqeVEBg8w6QOewOfdDNJvMvUCDXl9NYYO ZFyxhLQIL4jQg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 79852180032 for ; Thu, 7 May 2026 15:19:10 +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, 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-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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, 7 May 2026 15:19:10 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-48e56c1bf5dso6445115e9.3 for ; Thu, 07 May 2026 08:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778167144; x=1778771944; darn=lists.php.net; h=content-transfer-encoding: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=J/k4+HhZdbOTtox4oYW1jkb4cAuF4FDZRk/1IivWc6w=; b=mE67I8cXdvciVwjZsU1Co/wG0cfJXQ8iI6S5kiT84b2uyMAvp5ilAXWpKqNedMTgxw 5vbfCrm+FYT0wi/yElh1oyt+PG4yrjOdOtdg6SpfDC1FodEo5vVoOAbC/Rii2akWy2An C6vYet/vGmSMfVZ8hC15Twinq0uKEEmnRaVyD2hwUEbXKI9rD3s4gBK14VfF4OXXzfc3 kkZgz4GtN4kfMz14jTt5YQQUqlAoLWi3aq+7GXzE4Slz5aQb1jQtd7n5M1EnfrQi0MwX 5CJpdkYVPDdx5s0VtOuttCtXQxlZki07LicsSdOk5s4Vt1FdF/ucO5fX863jNab5imNy pF7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778167144; x=1778771944; h=content-transfer-encoding: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=J/k4+HhZdbOTtox4oYW1jkb4cAuF4FDZRk/1IivWc6w=; b=VZNZJ136wTQXCh0fOlo4HNvY/M8BEdBjNB2+qK0hxMEPO3FGJHt2adwZjxDm8/Ju1X G23NTnadpL1FOELN7k/puJH6YIEYlwyIB8gZdBZinGcs9KPjLYwHA1QOKMyBpEnnPRwM gxOBfUnA8khVCptq2JsApSLcHJqtguT0bQnYgH0L2fYRtRj1oTMySUBFfJDQkYrFAwUT KMuRRjUldJQ3LFaJ7PyzyCJorSYv+PFzJ8XJNNqDuTYos5cGOceUfTYdq8bsNjHWSqNc gMrYfLyZzluRwF0OyT9JYOX82urUcup0BS2O/sHTWJNtlkSY7PihVGnrJdkRIeIItpCK 81hQ== X-Gm-Message-State: AOJu0Yyl5L9kzE1tP9+nDrhMH7CTt/kEkT7nNQ/NH+xBTdsjRz0rPC2V QJHxeM/08VkeNl3bJnD+V+hgpulnA+SlNg0baxCHMIIaYeqzxrXUB4/VMGfJjw== X-Gm-Gg: AeBDiesnkfKMJEP01g0Cn6GsO5tx30b8ojjUvAdz40Za2b/lzczJqTf3CXAGF/YDIHX j2Jn84K09ZF/eMrT/3ChHtUr7rooB9oUyLZK/0ZynZ6gqLrIyIvzf5dk9x3dddRkhR/KzjpuG0T kXF8qzfZ7M3O+rhlwYza/IxjGnOWzlquw8Hf8bP52mmDIIeoPK5Splym2gge2HATBn6RxaIiFrA q6CveHWw9JkUj1eDhox/CBh5REDATxQfUPqquGr3Kx+4xKFhZZ3uOohQrjTtBBk1wuVCGMNXxXi X9gd08P5o41UzIG3yl3t5ZdrfkqnvbC24/0fjj6taGbTr1dsRgJuwp/SgRF121LCboGKnhBitIb 2m8q1EmucYYt1mtzFg+5Lmh8rhkyzv9tI7lhRKpH5D2dwunANJV8G+1M+cb/2fAilvjSIlMfDMd onYuPVDsTHp824IkZ1QxA1z9CjwABj5vLHmMHv3CD9Gpd3K4I7GMaiI9dXRjHNZP8iWREjlXWM7 31oOXeO5uHCJKQ9QUAm2+JXoeIY X-Received: by 2002:a05:600c:354b:b0:486:fa35:aef2 with SMTP id 5b1f17b1804b1-48e51e0c802mr133012065e9.4.1778167143616; Thu, 07 May 2026 08:19:03 -0700 (PDT) Received: from [192.168.153.252] (laubervilliers-656-1-64-146.w82-127.abo.wanadoo.fr. [82.127.89.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e538d2878sm208743125e9.15.2026.05.07.08.19.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 May 2026 08:19:02 -0700 (PDT) Message-ID: <80bfec8c-821e-497b-a445-8ecf18860d41@gmail.com> Date: Thu, 7 May 2026 17:19:01 +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] Scope functions Content-Language: fr To: internals@lists.php.net References: <0187D382-80FD-432C-B0D5-B0F9D8783419@hotmail.com> In-Reply-To: <0187D382-80FD-432C-B0D5-B0F9D8783419@hotmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: pierstoval@gmail.com (Alex Rock) Thanks for this RFC, here are my 2cents: I think the current syntax is too close to current short closures, and since it allows multiline closures, it would imply that by default all multiline short closures are scoped, which is not intuitive since traditional closures don't capture by default. Instead, I think replacing the `fn () { }`  syntax to add a keyboard indicating it inherits the scope would drastically help making it more intuitive. I would imagine instead something like this:     $externalVar = 0;     $closure1 = scoped fn () => $newVar1 = $externalVar++;     $closure2 = scoped function () {         return $newVar2 = $externalVar++;     };     $closure1();     $closure2();     var_dump($newVar1); // int(0)     var_dump($newVar2); // int(1)     var_dump($externalVar); // int(2) This way, for the first case, the only new information that `scoped` brings is the potential existence of `$newVar1` after the closure's execution, and for the second closure, it makes it explicit that all variables in the closure's body are shared with the parent scope. WDYT? Le 06/05/2026 à 22:09, Bob Weinand a écrit : > Volker and I drafted a RFC: > > https://wiki.php.net/rfc/scope-functions > > Please consider it and share your feedback. > > I hope it will alleviate pain around some of the most common forms of > Closure usage which is "execute this now as part of the called > function", which currently can require a lot of "use ($variables)". > > For me the primary use case of use ($capturing) was always "I need > this function later and want to explicitly document what escapes my > function". This, however, required this straightforward usage of > Closures to also document every single usage of a variable. Which is > really not that beneficial at all. > > Thus the scope functions as proposed will be able to fill that gap in > future. > > Thank you, > Bob