Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129622 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 3ECA11A00BC for ; Tue, 16 Dec 2025 16:50:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765903819; bh=9ksC0VWcTc2W0aazN1G+Kg8m3wTFRxlEWuurwuk6S1M=; h=References:In-Reply-To:From:Date:Subject:To:From; b=oHyMhkL+RNnVZ519owav0AmlM8y1woG4aUfwT9uNWWNqxaULkKHI9yky4UX1a3QOx W5uYmVMOyTQhCRbrRSDyb/8RW7lKredmL4yfa7pDHBYfEagyOLdW61Q1icmHcTqz4K 3V+sej0FoMEtO3Wlakkbb1dD0Q0ZYqZvZY2z9KSR+Rycx0rk6qrKG22eqzz2K3hGWo WAEB13fta6jdt3ZR3rDn3HK+3LN4KT4iTNHlXacYkpqoF7lkN4UrrKM28eN1EXoKFQ E6nNKaLrU8vn4k+E0J4tRRWsjlere9FZX8MispUNAqXUvjOkBmJMwyXglx88NsEqVM 0qzuHMWK+ifOQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9C9A9180209 for ; Tue, 16 Dec 2025 16:50:18 +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-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (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 ; Tue, 16 Dec 2025 16:50:18 +0000 (UTC) Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-6446c1b327aso794856d50.3 for ; Tue, 16 Dec 2025 08:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765903812; x=1766508612; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=1cLv9apySxJtttr1o//byeed5oGY1+aqAuLGtfAyMSo=; b=RDZN7IsdYivEa0l7Gky1Z4oQnhITGyBt7IT/W7Qk+1gto5kNySab3fOP6iVMp6L+LW yAaRte8qLbIYsi0KHNeAhR75dt6yTfZH6onCUQGcigm22j4ZzOW3dokVbzp4wTh7J6M+ Z/iWc1uPTbhYotmMnDNGjBJ/2tW34vO3tWVyRvXuNkaLosI/+BBLF5rSXRiaG3iLACwO 8N02s8TfzvuTPweGOx/gEZ+0CATHlHYdvmSezBSWAqeZoL1n8WhaHMNOli8tdmyzbIpY EPoGDp4HXiAJy33T+UbrryyXDFc8YEt0HsGawpikXRzbNFW5Hw+oDT4hsoe2Ofl6TgzH 8+mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765903812; x=1766508612; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1cLv9apySxJtttr1o//byeed5oGY1+aqAuLGtfAyMSo=; b=s2d2EBY7tcoKDWgjwV5dNHs1xktob6yJ0TyZGyGRJMaazN1+hCAJboz2xT04S75NWn Zo1ucJBpx+mVwqb2Y4O6NhIvyeQLQt0KOSTa/JgpUVUM2yFYuqOBqrpzUf6P6mM7oTEe mA5YpliLgTMeC+CdrsuYsq0kszxr4/XUT4vLV1HmSZYZZgO8vFofwnVt6FaCy69MBqBT 5MRBx1b+GMHzqY4DZgn3g256H5q3T4hIAPxEXpppBfrSvrUJjA4hEKXnuN8iQurQHhxx yrRpf+xxfq4f9B38DTcv7K0wjXq03yd3EJl1s5vJJwJTOmlWh6dxUuYpzQl9GJ/LeUtR FnOg== X-Gm-Message-State: AOJu0YzYnR+egk27nCdx9ts7oyPNyeuowI0Bk+HvX+MsGHpYzBTzF0Gt tIC4aWh4/if5AhzRyhmxIV29ER8FjRrqzCYt4bL22ihNr4IlEL5BS3UoccvfU3QhpeDwqsXd4NI tYw1u/H7sojqk57e31y5tPNbfRrPu1d2moCZLMns= X-Gm-Gg: AY/fxX7U4ngIhLAXotW3JUeo8cVlGHoE+QsFjc6rlQbMQwjlpbYlk9w5vlwjRv4grhU iOOuybUJj5ggxhyWTIDxF+58mju7ZRejvxgWj4/gVK8npV9PS7O8SfFSSCT7mak3FV9cdB+yYV4 1FRMbkWoYWsoYH4iwkq+WzavIKfSENhIBY2EOajwWf4MO/qd6XuhAx6Qp+lynoP+Bgi0SJY3F9/ ztaTrajQ6v04Vv0gQJXHWZ0tcBgSo90AxiKMRgia5yxIwGcVG3iNVMJEj8otkLoxDmnaKYHnmkB yGQlzhFg06VaDuegcFuB242eE+GRLRe1zSHqQvk= X-Google-Smtp-Source: AGHT+IG/LrKxvB+zbL8QYvDdTC5dtMJCjxe9HZtiRNO8ToGSu5yC/jxBhqVo+5dJtE7VmHYskneEhugqyY1t1Sl37rg= X-Received: by 2002:a05:690e:1388:b0:644:6adf:cbf4 with SMTP id 956f58d0204a3-64555651786mr10549525d50.4.1765903812281; Tue, 16 Dec 2025 08:50:12 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> In-Reply-To: Date: Tue, 16 Dec 2025 13:49:35 -0300 X-Gm-Features: AQt7F2r7zNGagyjKQVOi4SinyUjOMbvvVyft6u2piSu3JE4DPWz-KN3vdBXnZQQ Message-ID: Subject: Re: [PHP-DEV] [RFC] Context Managers To: php internals Content-Type: multipart/alternative; boundary="0000000000007048f80646148515" From: deleugyn@gmail.com (Deleu) --0000000000007048f80646148515 Content-Type: text/plain; charset="UTF-8" > > First, yeesh, where were y'all 2 weeks ago? :-P > I searched for the `as` vs `=>` discussion on the current thread (ref: https://externals.io/message/129077) and it didn't exist until now. Then I found the discussion happened on the Examples comparing Block Scoped RAII and Context Managers (ref: https://externals.io/message/129251). I wasn't following that discussion because I thought it was mostly about comparing both implementations and taking knowledge from it. I didn't expect *that* to make this RFC to change without it being discussed here. > Second, I find it fascinating that there's so many different > mutually-incompatible spins on what => means. As argued in the > short-functions and auto-capture-closure RFCs from a few years ago, => in > nearly all cases currently means "evaluates to." > > $arr = [ > 'a' => 'A", > 'b' => 'B', > ]; > > $arr['a'] // This "evaluates to" A > > match ($foo) { > 'a' => 'A', > 'b' => 'B', // The 'b' case "evaluates to" B > }; > > fn($foo) => 'bar'; // This function "evaluates to" bar > > foreach ($arr as $k => $v) {} > > The last is a little bit inconsistent, but can still be read as "$k, and > the thing that $k evaluates to." > I think the problem might be less about the true meaning of => and more about the context that it applies to. You can see that in 3 cases of the arrow it involves some sort of key/value pair (2 array scenarios and 1 match/case). In the case of arrow function, like I said before, arrow functions are kind of a standard that stand up on their own. And even then, the "evaluates to" is only partially because in arrow functions the evaluation does not take immediate effect, it is parsed into a Closure that needs to be invoked. For instance: ``` $array = [ 'key' => throw new Exception('Stop'), ]; ``` Here, the arrow evaluates to an exception that is immediately thrown. ``` match ($foo) { 'a' => throw new Exception('Stop because of A'), 'b' => throw new Exception('Stop because of B'), }; ``` Here, the evaluation is more loose and it only takes effect when there is a match, but it does take effect. ``` fn () => throw new Exception('Stop'); ``` Here, the evaluation never takes effect if the Closure is not invoked. In these 3 cases, we can see each having its own evaluation rule: immediate, immediate only for the match, and delayed. If I were to put into words, I'd say: array keys: evaluates to match: evaluate to the matched key arrow function: parse the syntax, does not evaluate to. ``` foreach ($arr as $k => $v) {} ``` Here I don't see it only as a bit inconsistent because it's not really evaluating anything anymore. It is assigning a value. And this is where it blows up for me. The first 3 cases we can argue semantics and point of views, but they are minor nuances. Still, they're all cases where something on the right is being evaluated for a reason on the left. On foreach, $v stands on its own. It's not affected / impacted / dicated / evaluated towards the left at all. It's not a bit inconsistent, it's completely different. And the syntax for using () is largely similar to foreach, which is why it should use `as` and not `=>`. foreach ($iterator as $key => $value) using ($contextManager as $context) We can see that the only place where arrow ("evaluates to" / =>) is used inside an instruction is in foreach and the syntax is split away from the array itself because the keyword `as` is separating `$k => $v` from the $iterator. I can totally see an argument for: using (new ContextManager as $contextManager which evaluates to $context) using (new ContextManager as $contextManager => $context) Here, the return of `enter` would be [$this, $context] and the syntax falls into place with a symmetry from foreach. I wouldn't strongly push for this syntax because the following also works using ($manager = new ContextManager as $context) In any case, I don't have a vote and I really like the RFC in general. With proper IDE support, I'm sure we will all get used to =>, but from where I stand that's going to be really awkward for the PHP syntax. -- Marco Deleu --0000000000007048f80646148515 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
First, yeesh, where were y'all= 2 weeks ago? :-P

I searched for the `a= s` vs `=3D>` discussion on the current thread (ref: https://externals.io/message/129077) and it= didn't exist until now. Then I found the discussion happened on the Ex= amples comparing Block Scoped RAII and Context Managers (ref:=C2=A0https://externals.io/message/12925= 1). I wasn't following that discussion because I thought it was mos= tly about comparing both implementations and taking knowledge from it. I di= dn't expect *that* to make this RFC to change without it being discusse= d here.
=C2=A0
Second, I find it fascinating that there's so many different mutually-i= ncompatible spins on what =3D> means.=C2=A0 As argued in the short-funct= ions and auto-capture-closure RFCs from a few years ago, =3D> in nearly = all cases currently means "evaluates to."

$arr =3D [
=C2=A0 'a' =3D> 'A",
=C2=A0 'b' =3D> 'B',
];

$arr['a'] // This "evaluates to" A

match ($foo) {
=C2=A0 'a' =3D> 'A',
=C2=A0 'b' =3D> 'B', // The 'b' case "evalu= ates to" B
};

fn($foo) =3D> 'bar'; // This function "evaluates to" b= ar

foreach ($arr as $k =3D> $v) {}

The last is a little bit inconsistent, but can still be read as "$k, a= nd the thing that $k evaluates to."

I think the problem might be less about the true meaning of =3D> and m= ore about the context that it applies to. You can see that in 3 cases of th= e arrow it involves some sort of key/value pair (2 array scenarios and 1 ma= tch/case). In the case of arrow function, like I said before, arrow functio= ns are kind of a standard that stand up on their own. And even then, the &q= uot;evaluates to" is only partially because in arrow functions the eva= luation does not take immediate effect, it is parsed into a Closure that ne= eds to be invoked. For instance:

```
$array =3D= [
=C2=A0 =C2=A0 'key' =3D> throw new Exception('Stop'= ;),
];
```

Here, the arrow evaluates to an exception that is i= mmediately thrown.

```
match ($foo) {=C2=A0 'a' =3D> throw new Exception('Stop because of A'= ),
=C2=A0 'b' =3D> throw new Exception('Stop because of B= '),
};
```

Here, the evaluati= on is more loose and it only takes effect when there is a match, but it doe= s take effect.

```
fn () =3D> throw n= ew Exception('Stop');
```

Here, = the evaluation never takes effect if the Closure is not invoked.
=
In these 3 cases, we can see each having its own evaluation = rule: immediate, immediate only for the match, and delayed. If I were to pu= t into words, I'd say:

array keys: evaluates to
match:= evaluate to the matched key
arrow function: parse the syntax, do= es not=C2=A0evaluate to.

```
foreach ($a= rr as $k =3D> $v) {}
```

Here I don&#= 39;t see it only as a bit inconsistent because it's not really evaluati= ng anything anymore. It is assigning=C2=A0a value. And this is where it blo= ws up for me. The first 3 cases we can argue semantics and point of views, = but they are minor nuances. Still, they're all cases where something on= the right is being evaluated for a reason on the left. On foreach, $v stan= ds on its own. It's not affected / impacted / dicated / evaluated towar= ds the left at all. It's not a bit inconsistent, it's completely di= fferent. And the syntax for using () is largely similar to foreach, which i= s why it should use `as` and not `=3D>`.=C2=A0

= foreach ($iterator as $key =3D> $value)
using ($contextManager as $co= ntext)

We can see that the only place where arrow = ("evaluates to" / =3D>) is used inside an instruction is in fo= reach and the syntax is split away from the array itself because the keywor= d `as` is separating `$k =3D> $v` from the $iterator. I can totally see = an argument for:

using (new ContextManager as $contextManager which = evaluates to $context)
using (new ContextManager as $contextManager =3D&= gt; $context)

Here, the return of `enter` would be [$this= , $context] and the syntax falls into place with a symmetry from foreach. I= wouldn't strongly push for this syntax because the following also work= s

using ($manager =3D new ContextManager as $conte= xt)

In any case, I don't have a vote and I rea= lly like the RFC in general. With proper IDE support, I'm sure we will = all get used to =3D>, but from where I stand that's going to be real= ly awkward for the PHP syntax.

--
Marco Deleu
--0000000000007048f80646148515--