Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119706 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89462 invoked from network); 15 Mar 2023 10:10:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2023 10:10:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFF9F1804F8 for ; Wed, 15 Mar 2023 03:10:44 -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, 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-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (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 ; Wed, 15 Mar 2023 03:10:44 -0700 (PDT) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-5416b0ab0ecso228829547b3.6 for ; Wed, 15 Mar 2023 03:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678875044; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZK9VJ9iN1aG3mZvT3ymvaPbMDXb6HPcZHSeCuwElZHQ=; b=G/oOvC+q6HUamwHQ5/9votDHVyETvmVEqi3jZnebKTQ+Ms3EtOb7+O2Qhk2iLGwi/f L5t4qc7LsWEFzUnhn5TKe5KfDA9ZUbQOeciEvwYlEL2kQzFw2mR8izJir4jrJZkjec/L ubyS2M9KXXol1+I7ahpEJspwyECJHRqtbPvM5dFcNbuZSLTgcghauS8+FGpqaVMsMuB4 q3kkIp1e1JFGP+5ttdBYnMbN6HQVv4m6YYPSS8oCJ4jBl2jhN9syF+a3CuKY2rEzZPmz w+2kHXzOCprwFdUQfr0p7fM/19QO6BtjDiuKHZHGzb+hMru2FSArPa0CYdZxS4uTpbav R8Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875044; h=content-transfer-encoding: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=ZK9VJ9iN1aG3mZvT3ymvaPbMDXb6HPcZHSeCuwElZHQ=; b=zXVvrb6RbHOLmAY46sXiEPi98K1oxAqasL5SPy2SiNV4U6FuzsSr32sXDhBbXGcCAC OzbAdex8CnfXy/UXwp+YrX1J1hvsc+qxUr1ha6AiJ152IoAEXgYCuRrFGyBgdBWOaek0 hDYMkyECx+Airvxm/CAF0ZFfhzSKFVHYdqJde3GQFtSlwvpOKVSHZq1uNVoEoOfY8c2m c1ZUVZCzrt+aUYzggpRsNIoaiDdz5FNNlZG4BWIgslWvoPBHwBaOC1g5sipiMCN5SYPS F8NaGExj0VUEhLFFhzPV2/81tlIgteUXjfVu7Kbst0ZjAXSJ6Mu5x2VV7ilAfcMu6Vd0 c9dw== X-Gm-Message-State: AO0yUKWkSWYKkDySUczjw2reVhAj6abPpjjnaThPVfXi6MtTQ4bdDsUF 2HOjoKKeKBLdH3gdJ/PdqcrdZeE742CLcbXX0Es= X-Google-Smtp-Source: AK7set8EQ733LUY/jeBTWnLRj/szy6fOLMGLxaKBS3s/F5gjZakdSneFQH4gl1Zj0MBEV7N1ZhFMrMZTY0wmDzQMW54= X-Received: by 2002:a81:b70d:0:b0:541:9063:8e9e with SMTP id v13-20020a81b70d000000b0054190638e9emr7597574ywh.2.1678875043810; Wed, 15 Mar 2023 03:10:43 -0700 (PDT) MIME-Version: 1.0 References: <8a9a04b3-45e6-47dd-dee8-0f524e49bd37@gmail.com> In-Reply-To: Date: Wed, 15 Mar 2023 11:10:32 +0100 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Brainstorming idea: inline syntax for lexical (captured) variables From: landers.robert@gmail.com (Robert Landers) On Wed, Mar 15, 2023 at 8:38=E2=80=AFAM Rowan Tommins wrote: > > On 15 March 2023 03:28:39 GMT, "Alexandru P=C4=83tr=C4=83nescu" wrote: > > >How about first implementing use() for anonymous classes first? > >Something like: > > > >function foo(int $outer) { > > return new class() use($outer) { > > public function getIt() { > > return $outer; > > } > > }; > >} > > > I think it's a lot less clear exactly where the variable is being importe= d to that way. Would you still be able to overwrite $outer as a normal loca= l variable in that function scope? Would it return to its captured value ev= ery time the function runs? It's different from capturing into a function, = because you're not just adding a variable to a single existing scope. > > Just allowing the captured var for property initialisation would be less = ambiguous, but having to list it in use() and then in the property list wou= ld be the same amount of code as you can currently get to with constructor = promotion (see my first example in the thread). > > From what Ilija has pointed out, the implementation of actually getting t= he values into the right place is going to be harder than handling the synt= ax anyway. My current feeling is that if it's possible at all, it will end = up as a shorthand for that constructor example: declaring normal properties= , and populating them as the instance is initialised. > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > The outer variable would be captured by value, and carried around with > the instance, like existing closures. For what its worth, there are ways to get references inside values: https://3v4l.org/5q93F Other than pointing that out, I like it.