Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120038 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92334 invoked from network); 14 Apr 2023 06:52:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Apr 2023 06:52:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6CEF9180084 for ; Thu, 13 Apr 2023 23:52:26 -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-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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, 13 Apr 2023 23:52:25 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id e16so3158699wra.6 for ; Thu, 13 Apr 2023 23:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681455144; x=1684047144; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=IsvsLq6PTwuslcN8mhlOaqQqlD/28cGN2h1L85rjGGY=; b=EQUn7xMqkGE8mpmXqBTZUXFR8SAeTam1Sz5EB4PmX8v8e/XZ5PiyncQqfVs4Vetzrp Q42ifB0zlCIDri+4eyTgOu1diWNmHjVl1bCpP8UxoW42QgPflHTw+mWTpps9kAJ1Lcgh 0ZD/h03kTz+yyMnQBw8J1No/vH3/rCQ0yHoxeRPPi2QHIfJX3GmuFawEYKcLZYIq64Px YiFhDOQin4G5tZ7crwZYzEAomCe91H7PUHBYvsIpTs+I+PLPoiaJxHfVMmiuUix//b7I K402CMpjm46lYQ4tWKzkQ1K6/rv3/00HVge6QICDCzCvQfxYZFMjG8lL6cQwX/Hh3PWa sgLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681455144; x=1684047144; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IsvsLq6PTwuslcN8mhlOaqQqlD/28cGN2h1L85rjGGY=; b=CabcbDDMg0YKuVRlSNmTl14V17E4FspmEldK0BoGPO49nqJ20IxfmQ+Z+QfUnDKrqP 6GsV/Yz1mouJAUVBUNkf+KgEW+j5E/Ey4PZkTC1r5xwQftjGpC1DQdQ2HZZ/FJoDfL+n MKWVcSnvs7zftl4Jl9dy68vQ85Ikw7fIB+ITE+MiWlBdxB1cXEUYHXGS7ZYEgcU6JxVh JM+H3h/3/z/2H/Qe9dqwMmeiLJWAYOXusrzBQsNWu5sb0gguU7FsZVF9AduaIbpu9T7S k4Jb7e7lbB+QPpEoAjc91w93bS6Xmw3D5itQLwuMumLvxAg7yuYy6zTsO6VSb5wemuol RrbA== X-Gm-Message-State: AAQBX9fgGXsCHAxvyKWemKQnHGFEPXOAK/eOfR2LfVEdR3RAcaV4RSu5 QoAshV/xb3S5FmKHnQBEgf3SkrIg3UA= X-Google-Smtp-Source: AKy350aSyV/Y+spPdaBPqk8Bi9688/9ILtqaIlfy0WMVKKiGdbJt2OCBFR4l7snwcqrHlK4zQ3WrTw== X-Received: by 2002:a5d:5706:0:b0:2f4:e2f3:b478 with SMTP id a6-20020a5d5706000000b002f4e2f3b478mr3163862wrv.7.1681455144495; Thu, 13 Apr 2023 23:52:24 -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 v11-20020a5d43cb000000b002f490a0cd1asm2820059wrr.92.2023.04.13.23.52.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Apr 2023 23:52:23 -0700 (PDT) Date: Fri, 14 Apr 2023 07:52:22 +0100 To: internals@lists.php.net User-Agent: K-9 Mail for Android In-Reply-To: References: <8a9a04b3-45e6-47dd-dee8-0f524e49bd37@gmail.com> <52a5a80d-f03f-5e96-4188-272a705e3fdd@gmail.com> Message-ID: <6D8558DF-FDD1-4B04-920F-7EDDC38DE532@gmail.com> 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 14 April 2023 05:35:39 BST, "Micha=C5=82 Marcin Brzuchalski" wrote: >Have you thought about not populating property by default but instead: >* adding "use" language construct as default to all methods? >* adding ability to assign variable values from "use" to property if need= ed? > >Like desugar to >$c =3D class ($a, $b) use ($c) { > private $c =3D $c; // optional, not required, no conflicts > public function __construct(private int $a, private int $b) use ($c) = { > $this->c =3D $c % 2 ? 3 : 5; > } > public function something() use ($c) { > return $c; > } >} This is closer to what I originally proposed, but with different syntax=2E The challenge, as was pointed out to me, is that the anonymous class is co= mpiled as a reusable class definition on first use, and a new instance cons= truction on each execution, so you have to think about what happens at each= stage=2E In this example, you've got to first compile something where $c is an open= parameter of some sort, and make it available to all the contexts where it= might be used; then, when you create the instance, supply a value for $c, = and attach it to the instance somewhere; and finally, when something() is c= alled, look up that attached value and make it available to the method=2E In other words, the use() clause on the class ends up acting like a constr= uctor parameter, and the references in methods end up acting like property = references=2E It's a lot of extra complication to duplicate things the lang= uage already has=2E Having played with it a bit while implementing, I also like the concisenes= s of objects with no explicit body at all: $who =3D new class use ($firstName as string, $lastName as string) {}; echo $who->firstName; Regards, --=20 Rowan Tommins [IMSoP]