Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129611 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 2AE211A00BC for ; Tue, 16 Dec 2025 00:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765844834; bh=DigoQFqyvrpnANjJk4O2uQ8lJ4/Tjn1PKT5d0N1QenY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bPxHvVjhy+X1BdRFNI7f3vMR1x39kb/NmvLMU/rT4Z3FYengqYEXHqvLJucYvmYq7 n8l37diKfRIss6QXQs3HptgoNYqjQyiC6C2M2F6fylcvuoLCDcJtth8Ga5bMh1lyZH C5SspSy9aX4HZFamJa1vEmDGHSSAnSZdWKhZH4ev0PhSO5KNZnlgEqpeGXLzE2vWhx obG+puL9cxJyQlilqzKSTP557woYR6nqAnSxi95RCYszjYtsx0cJrDOF2PrzVxQRBy KiAe5BKs5t35ahUfugo8TFPGdcLKkREH3+tEVZOlO3YUXxEYNm3bsi++DccCblCoS8 JeLn2wcddyFMw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D454F180050 for ; Tue, 16 Dec 2025 00:27:13 +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-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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 00:27:13 +0000 (UTC) Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-450b7ee2d4bso986617b6e.2 for ; Mon, 15 Dec 2025 16:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765844827; x=1766449627; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yG4Yzcv72mejJ+KYyx0LY3RZvkAnOm1DfMdekvK7T8A=; b=RPpuoy200BjqYrq9p/Cbhp2QifqmRXrdRKESYBMusHL3K3vnPSf3T4X7ivpp1gt7xT YanZAyWBdxucJVuwSdeKRO7Itcqj/lOi1aiRydPbmpvVzo4zDmU9UbfvR0wvFt3/BJDW V+OPDtYcyw93Fij3LXNKxhRdwBQTmJ68nauS0orX/foRN5IlNV8Vu7lwQ485FqOqOlY7 JSEpqttUqgvy6iU5sU1jXNmbnkeGs2ReSri/ubGYcCdqA8wJsWGPhYu0zm1Nh7WM1yA5 EqX1sEeTAq8vTLkC6h1zv2dDMrZxfRACsGYFrxSItDUNYGhiSVm9AkPS77kYvhkyhJCi o3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765844827; x=1766449627; h=cc: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=yG4Yzcv72mejJ+KYyx0LY3RZvkAnOm1DfMdekvK7T8A=; b=FTO+zQyr8YqBcRavHcQP89/pJeH9zC1kL8A00Pn2RSbj4EpMFdbjulf9PDM2Z4ZYZp q8NtMFoFIXYM7lRllcEvAZoxFnHNB3kVbOrWZUhv5o+mP3+ypycvXWItCXFWsb8oOYOD bA6gjBG6AhwAIuwPWnajdfnq1a95Q0tG/wK7OfYyPbeuxo1aiffuplh8WQwYA+32T3x1 xQvTbg0aGYEH0wafqYwOhTsHQtjtr4NcXjPHubt8C29knjbOHbzRYAxHYdrS4G5E+Pts EefblrkBRDa9PJfidNnqAzQPEVWgXL6y2elypPO4SJK9kBhrDPydYFPAUbAw+Bexe9W5 Go4A== X-Forwarded-Encrypted: i=1; AJvYcCWKNeC4Z2ShSZo1RRFVoZkgJFTb7xa4uXq63EFm+Hoz0SsZUw7xex82qfV+I1jaLpyKOEMuMeusq7s=@lists.php.net X-Gm-Message-State: AOJu0YyGHFQxj7IQW33KWLAO6nlh479jW4QEgnie2RXs/V+xOnZJ0ib5 bA+KOTcGOhMY5ezYjfaxR8+B/T1B5aeGaImS4bzlr9WPNUF4OJGcmmJ9Z8idwKClFpoLdIZVSgf oOFUV8fN5+eudF6nIbAEsB0UO/fsttbkCbQ== X-Gm-Gg: AY/fxX4Q6KlewWi32aRzRxNzUAawjfbJB3msPguNh6L6xXSVS8ddwTqjqPxTYWmjAnr jvk8d+MjV+sfgUkTxNLXz6ed9gyGSV5T9d8QufVYHBzmuhV6VKDLKo2dXkbTb7kKJmFSdOrHLhg C6AgejYk0lPwwoK+vsQ+PsDjSnWQV5GRIyLN/dy5WAM8N7pqvyX4RrZAJ6e45D4SJioCWV0Zpzd X1+3M9b3KkQKsfUywJDzJjhaaks9pAbNv/snWscKVYNsU96dfQ1TvUH2FlHi65PSA4D9XQBRSS/ TldDlEad6TOYHyEJClsaJIS0sIxy X-Google-Smtp-Source: AGHT+IFuUmU3k+Ut+lKV8tt2L9MznLXlamZXjD1Y/pfUfHODLb86QfRuXNfNRmOmSSci8ev77LYITMO/86KlyA3rNyc= X-Received: by 2002:a05:690c:c457:b0:78f:84dc:5631 with SMTP id 00721157ae682-78f84dc5b06mr11216227b3.3.1765844519423; Mon, 15 Dec 2025 16:21:59 -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: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> Date: Mon, 15 Dec 2025 21:21:48 -0300 X-Gm-Features: AQt7F2r6k-MpypUp2SWs7pSdxNatIvYR8qilR-XgPPAhajbA8q2tt7ol_fslTTs Message-ID: Subject: Re: [PHP-DEV] [RFC] Context Managers To: Ben Ramsey Cc: "Matthew Weier O'Phinney" , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="0000000000004f1397064606b705" From: deleugyn@gmail.com (Deleu) --0000000000004f1397064606b705 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 15 Dec 2025 at 20:01 Ben Ramsey wrote: > >> Since the only feedback on what to use for "as" was that =3D> makes sens= e, >> we have changed the RFC to use =3D> instead. So the new syntax is >> >> using (new CM() =3D> $cVar) { >> // Do stuff here. >> } >> > > Going to be controversial here, but this is confusing, because it operate= s > in the exact opposite of every other usage of =3D> we have. With associat= ive > arrays, the left is assigned to the expression on the right; with arrow > functions, the return value is the expression on the right; with match, t= he > expression on the right is returned. > > This is going to be easy to get wrong. > >> > I agree with Matthew. > > I think it makes more sense to reverse them, like this: > > using ($cVar =3D> new CM()) { > // Do stuff here. > } > > I think it=E2=80=99s still clear what this is doing, when reading it. > > Cheers, > Ben > I also agree with Matthew but the reversed proposed here looks very very awkward to me. I think the most natural thing is the =E2=80=9Cas=E2=80=9D b= ut I may have missed the discussion on why it had to be changed. Thinking of foreach ($array as $value), an item from the array (left) is assigned to $value (right). That seems symmetrical to using (new Manager as $manager) where the instance (left) is assigned to the variable (right). Also when using aliases on the top of the file =E2=80=9Cuse Foo as Bar;=E2= =80=9D as is also assigning the left to the right. --0000000000004f1397064606b705 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 15 Dec 2025 at 20:01 Ben Ramsey <ben@benramsey.com> wrote:
=

Since the only feedback on what to use for "as" was that =3D> = makes sense, we have changed the RFC to use =3D> instead.=C2=A0 So the n= ew syntax is

using (new CM() =3D> $cVar) {
=C2=A0 // Do stuff here.
}

Going to be controversial here, but this is confusing, because it operates= in the exact opposite of every other usage of =3D> we have. With associ= ative arrays, the left is assigned to the expression on the right; with arr= ow functions, the return value is the expression on the right; with match, = the expression on the right is returned.=C2=A0

<= /div>
This is going to be easy to get wrong.=C2=A0

I agree with Matthew.

=
I think it makes more sense to reverse them, like this:

=C2=A0 =C2=A0=C2=A0using ($cVar =3D>= new CM()) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Do stuff= here.
=C2=A0 =C2=A0 }

I think it=E2=80=99s still clear what this is doing, = when reading it.

Cheers,=
Ben

I also agree with Mat= thew but the reversed proposed here looks very very awkward to me. I think = the most natural thing is the =E2=80=9Cas=E2=80=9D but I may have missed th= e discussion on why it had to be changed.=C2=A0

=
Thinking of foreach ($array as $value), an item fro= m the array (left) is assigned to $value (right). That seems symmetrical to= using (new Manager as $manager) where the instance (left) is assigned to t= he variable (right). Also when using aliases on the top of the file =E2=80= =9Cuse Foo as Bar;=E2=80=9D as is also assigning the left to the right.=C2= =A0
--0000000000004f1397064606b705--