Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119719 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73916 invoked from network); 16 Mar 2023 09:28:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2023 09:28:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD0DC18054B for ; Thu, 16 Mar 2023 02:28:23 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 16 Mar 2023 02:28:20 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id bi20so742189wmb.2 for ; Thu, 16 Mar 2023 02:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678958899; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lvFVTehNgG6MQVbAAQD4a2VSNurJo4TKDENcsptXrcI=; b=mFtxfauO7MF1KqH7aQbVLVYpdAd5B+9iMctTlPdHQtw/8hLIOOqsBUemP6mwSHJriV wKXiAJEE2sT7nJUuNaUlZCxCanVZCKk5sPW5EqQ6L2dTZl7s4J+8Lf/IAvur89iXfGEx JRX5Uq1ORWW73qfS/z9QGEFKn8fPBIvndSNkw6qSE+4sfBe/DkCe0OwEutEUKj9iuVAR rQPO6kmjdj0MZGfSb08Io0pJExMbdxSLnaZ0A9zbJejbbtzm8KATqR+fTUzdSSrcqPok wJ2nngNsx67Ln804606eDnDLQ6zEDNqV8mi5ts66CuAFdS0PBav8H2F25Fyv+gmE7ctf BtIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678958899; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lvFVTehNgG6MQVbAAQD4a2VSNurJo4TKDENcsptXrcI=; b=3J7YRrSv3qEhOrJojN2xOhEUDBZ69ud30vbEgvW1azQdsInw6mvWCwRCVu4YRbNdjH XOZU6Nsk7qW8vQOjE/tJORuT3cAz5tnDbVK4Nl6IYLxMccLRzQMspbsE1tJQsFrwumMP SLXyukkGFK367iAU3BUw5AV5XxBf8e4QwDAZaQduiPNjKA4wEbVcnesYnxDmARuBtdbG RD01C03NgIdPEzbhjphSn1F9PCIxeBJwMPsP5au5WOg4iyuxyTCQVq1pmmXkhX2Obxh5 gZ04wNO7U3kW2La/hETtUeEihOUTEt2krW82L5Odud6ix1/gaZMdNgrEahk02NflQgdv pSyg== X-Gm-Message-State: AO0yUKXetlI0KmHvjzz/lI/azIccLsu4kH6B9jmoNTzIFIGWhIkl9J3q ump84gtUgbnYlhOKPsMS7vsO0WTKXP7XFoncobESSkxaaZfM+w== X-Google-Smtp-Source: AK7set8n5yyhdm/PSViyWb04chVto+kIwNG/y4EC6lVw9Yoaxtkvhy+/JZB+ZxWIQFxM412MhTNdK5FKAnhCNOdzV+o= X-Received: by 2002:a05:600c:3ca8:b0:3df:97fd:221f with SMTP id bg40-20020a05600c3ca800b003df97fd221fmr5921032wmb.5.1678958898853; Thu, 16 Mar 2023 02:28:18 -0700 (PDT) MIME-Version: 1.0 References: <8a9a04b3-45e6-47dd-dee8-0f524e49bd37@gmail.com> In-Reply-To: <8a9a04b3-45e6-47dd-dee8-0f524e49bd37@gmail.com> Date: Thu, 16 Mar 2023 10:28:07 +0100 Message-ID: To: Rowan Tommins Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000c23a6205f7011464" Subject: Re: [PHP-DEV] Brainstorming idea: inline syntax for lexical (captured) variables From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000c23a6205f7011464 Content-Type: text/plain; charset="UTF-8" Hi Rowan, I have been pondering for a while how to improve the anonymous class > syntax to allow "capturing" of values from the outer scope, and came up > with the idea of a special variable marker for "lexically captured > variable" - instead of $foo, you would write $!foo or $^foo (I quite > like the "upwardness" of $^). > To overcome the issues spotted in the thread, what about doing some sort of CPP instead of autocapture? new class (...$arguments) use ($outer) extends Foo { public function getIt() { return $this->outer; } } This would be the equivalent of this: new class ($outer, ...$arguments) extends Foo { public function __construct(public mixed $outer, ...$arguments) { parent::__construct(...$arguments); } public function getIt() { return $this->outer; } } And we could also allow this for better type expressivity: new class (...$arguments) use (private int $outer) extends Foo { // ... } Nicolas --000000000000c23a6205f7011464--