Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119705 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79801 invoked from network); 15 Mar 2023 07:38:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2023 07:38:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2E985180538 for ; Wed, 15 Mar 2023 00:38:39 -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=0.3 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MISSING_HEADERS, 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-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 00:38:38 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id c8-20020a05600c0ac800b003ed2f97a63eso467511wmr.3 for ; Wed, 15 Mar 2023 00:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678865917; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:from:date:from:to:cc:subject:date :message-id:reply-to; bh=b3hV+nfnd/SA+CcQcHi6l/Gp+CYxBtpt5IEP/fZT30o=; b=cNzqB69OHB9L8fPHGyvavNUodFLBZ6P0TuQS2pwPnmjxI1abCfyZHuV/kPaGcf7ggd eLjhWITlN3laRSVRIJLAgtnqOaI88EFIxYRAKttY3u5HAQ5zOOgdimZa4c0ibZ9cH9D9 GekBESwDncO+hVWdxIREEpLJ+xcWjlJBzUp4cUDZiDFZMhNsF5DEHG8gvXkuqMVwbfbx tp9c+EyLVGYGs6ql8hCYZUds46AnOPQDv9zt0f6PbmhFgp6Jg8lkyxXbqucUezTHqt7x rPgGTe9efvNm7NezB1n6XG7VGHp1KklVeSSrL8oYXeVxEI6EZYdfHhSQEJ+5cTP0T3Hr re/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678865917; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=b3hV+nfnd/SA+CcQcHi6l/Gp+CYxBtpt5IEP/fZT30o=; b=Tjdudk5sKeP/4esHM1/sODndGvmg3n2V/j6gtj2QLZWncl1dtQ+Xyi0Bj6wf/C5I2t 2Mr+x0T7B7t73sW0kQrlpYmABUkWeel54GxSSqm/4svMjAL+/UNRmsMessYWAenE/qeb y2H+2cETxfhxfnRnYFtzuxmt7fn7PiRv+4L4aD7hyv+4A5fAlYTf51k/9uN5a4zEFrhD +HgnpWTjpfuofDzczHki0BcF5oBdSN+Oo2+ehRcgA5BE0M3Lg+y9Y7Ml8lUQaOtawfhP qv0MUtnLPqBWIoarKPgkb7zGFAruI5eYt32IBor+EBbxm76Fv5wz0F2wEFvnpAF1o1iz Ko9A== X-Gm-Message-State: AO0yUKWxombhSuM+WXCuRAl8F5EvC5jCtWjMnCR4WdnIhFwv1/EfgUcm zxeJGnaWH+caJ9ZPx/H0CPynftXSSAw= X-Google-Smtp-Source: AK7set9BaqUG/Ytpi60VuW1+zMaNt4PLBM3E7V7ebIModtDDxTn7De4QhXVQdp2k98B5UMVLSxXFLA== X-Received: by 2002:a05:600c:a04:b0:3eb:3971:a2aa with SMTP id z4-20020a05600c0a0400b003eb3971a2aamr17613206wmp.25.1678865917607; Wed, 15 Mar 2023 00:38:37 -0700 (PDT) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c1d8b00b003daffc2ecdesm976298wms.13.2023.03.15.00.38.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Mar 2023 00:38:37 -0700 (PDT) Date: Wed, 15 Mar 2023 07:38:35 +0000 CC: internals@lists.php.net User-Agent: K-9 Mail for Android In-Reply-To: References: <8a9a04b3-45e6-47dd-dee8-0f524e49bd37@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?US-ASCII?Q?Re=3A_=5BPHP-DEV=5D_Brainstorming_idea=3A_inline?= =?US-ASCII?Q?_syntax_for_lexical_=28captured=29_variables?= From: rowan.collins@gmail.com (Rowan Tommins) 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 imported= to that way=2E Would you still be able to overwrite $outer as a normal loc= al variable in that function scope? Would it return to its captured value e= very 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=2E Just allowing the captured var for property initialisation would be less a= mbiguous, but having to list it in use() and then in the property list woul= d be the same amount of code as you can currently get to with constructor p= romotion (see my first example in the thread)=2E From=20what Ilija has pointed out, the implementation of actually getting th= e values into the right place is going to be harder than handling the synta= x anyway=2E My current feeling is that if it's possible at all, it will end= up as a shorthand for that constructor example: declaring normal propertie= s, and populating them as the instance is initialised=2E Regards, --=20 Rowan Tommins [IMSoP]