Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120303 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12117 invoked from network); 15 May 2023 20:12:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 20:12:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 09E70180083 for ; Mon, 15 May 2023 13:12:20 -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=-1.1 required=5.0 tests=BAYES_00,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-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 ; Mon, 15 May 2023 13:12:19 -0700 (PDT) Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-3f50020e0f6so4179945e9.1 for ; Mon, 15 May 2023 13:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684181538; x=1686773538; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ccAZOBbyiScilLMuOYK+v6Fi9m4DaNNA5LN8zc0ydAE=; b=hp3tkpCq+BL9ZmoaHzlcpij+UB0CK3Tzk82kNAPYAKTBNWyVlBaJVyiOXBW1ayuStX Sttiefq4HBk0rU0nGYv1faJMtYZJqSj8K4MaUJAaNatjXc6iMJdDh4p9FZgie/075lVc jT6vihoaOyStmLnaL1tCZCPOjoP1kp1LncDdeSi/7k0MGndQit5MGt7X2MfIAqN28ZLj bT7wliqCFzCaTtoPicoKMQU8cLu0H5zp1AIsAbDmWGENvLEzvzL+ojVYxRrjGiB6IzWT srHPmVkD0C5MMkR9dXUtnq+6yP+jCELzUOtBGRDD4oyNUELRa5KISlu0R87brDzyX3GE YCQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684181538; x=1686773538; h=content-transfer-encoding:cc: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=ccAZOBbyiScilLMuOYK+v6Fi9m4DaNNA5LN8zc0ydAE=; b=VMUMvdYI3HHQq3z9066/li6+vEbYwxV3e1XsXZHCb68FGNFcORn9t4jlAy92otFv37 kpVvV+nkHVx/AfbMf0+VR89PuLgf2o9cqJb+IhHxKk5/g5RveXWPGTWZ78lprHMjUNUN 32K644LzJytrPYSwyvhGcG7ciS4jINaVTzuSKdca89g+ydH6ZbuPqbS6lM6DicUOnvNp R4BlcT6MAQFea5r2tfTy9ksqyoN4Emi2pO8m5ychcag4wHwNA/3h0erFjVnwg1uEx6Ov 1Q3CFZDWiwS6TWPIeNkkt3EiZLhOnm0DgSTlJL31JvzDB0YHRYuE7rh6rXOQVfXJgsCV mghA== X-Gm-Message-State: AC+VfDzWFz4yTyKi9+2x9qEUbtSbBSg8HZlBCcC30wc54Xe7f0GeZWWS TzqLqlTtJd0GSPsVhoP95CFGA084fB8qRkPAT8BJi8YZL6Z3yg== X-Google-Smtp-Source: ACHHUZ6dOWMzNOViS25+2OQSh/JqxzF9yz173bYJNp2lvK4qRiuxVXP3uR1nkvXmFLb5X6kU8fAAgHlbEoYpdm5+9Jg= X-Received: by 2002:a05:6000:11:b0:307:cf5e:28a9 with SMTP id h17-20020a056000001100b00307cf5e28a9mr182069wrx.5.1684181537587; Mon, 15 May 2023 13:12:17 -0700 (PDT) MIME-Version: 1.0 References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> In-Reply-To: Date: Tue, 16 May 2023 03:12:06 +0700 Message-ID: Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Property hooks, nee accessors From: the.liquid.metal@gmail.com (Hendra Gunawan) > (Also, when replying, please please remove duplicate names from the to/cc= line. I just got double copies of everything in this thread this morning.= I'm on the list, I don't need to be CCed.) Sorry about that. Not my habit before. > For the second, the problem with omitting the {} is that it creates yet a= nother syntax variant. That makes it harder for the parser, for static ana= lyzers, for user-space parsing tools like php-parser, etc. That's more wor= k for everyone for fairly little gain. Sad to read that. Making one of them as the shortest shorthand feels like a picky decision. Some people agree with ```get```. Some people will argue that ```set``` deserves more than ```get```. Personally, I choose ```set``` to be the shortest shorthand as it is more relevant with constructor property promotion and value object. Do we need a 2nd vote for this one? > Removing the {} entirely from all forms makes it harder to denote where t= he list of hooks begins and ends. They would probably have to be comma-sep= arated, like this: > > public string $foo > get { return $this->bar; }, > set { $this->bar =3D $value; }; > > Which I'd argue is harder to read anyway, because you have to be careful = of the very small , and ; marks. The {} is just easier for humans to parse= as well as the machine. Looks like it's not more simple compared to the other one. > What we really would need here is asymmetric visibility. No set hook, bu= t make the property private(set) so that trying to write to it gives an err= or, as it should. So if asymmetric visibility is implemented, will my code be this simple? ``` // cache once and freeze, // and without additional hidden property public private(set) string $prop1 { get =3D> $field ??=3D $this->heavyTask($this->propx, $prop->y); } ``` > For cache clearing, the best way to do that is probably with an unset ho= ok. That's been omitted from the RFC for now for simplicity, but that soun= ds like it would be an argument to introduce it later. I was going to write about this one. IMO, why do we need to provide additional hidden properties, when we are able to store the cache directly into it? Obviously we need a ```unset``` hook.