Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120224 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32863 invoked from network); 10 May 2023 11:35:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 May 2023 11:35:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 156F4180543 for ; Wed, 10 May 2023 04:35: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=-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_H3,RCVD_IN_MSPIKE_WL,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-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.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 ; Wed, 10 May 2023 04:35:38 -0700 (PDT) Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-54fd9c0e435so559008eaf.2 for ; Wed, 10 May 2023 04:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683718537; x=1686310537; 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=1SmSRp18kiLdj8MYs1UqIimm9kXxnUjZ0W0JIZAKDgE=; b=Tud1weDFBVvrtR8jGXpYLA87PoQLnYm/rCeXmOHpx30/DH4DNmI9R+WPQp3Zf5VWC5 9UJtPBWOnOS5MSmKm0Tby2s3IzayMPxT3IsqmHwc187hSeg/Oa3RDT9NHIGir6ome9Hw cYLag+mlYkNbS3LwLKvHYSaziZxHklvWV77DmoPjek8maDOPLBUzHddcxHyijYH/MYAR xoDDsoKSULKFk28nLYVaTo7tH2G9pLv5/goedtLJuXXUi9+xDZ4a9m1VuJdKza0ZUUJB hkDONFknTsOFcCvrbA/mZ1boIeJXUWC+m+5lsHgl9fuYOgKpyHqe3uLQ75v0hyfsghgy UfjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683718537; x=1686310537; 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=1SmSRp18kiLdj8MYs1UqIimm9kXxnUjZ0W0JIZAKDgE=; b=L/7jO7KH8cpyU40npE1SRVvx0E46TKhfxfDkBlnngK8rn06d/4GMnpiWThbcAZtY24 +MYbmTjFj/8OmdgQ/xY1C5WuE6dsd6hyvHjiOIUS6JuInPthz+HocKlq+KX4/WzJ0LnW 2NU1UuXk2nfuikcC6sxEeab1EkxxH+UmaO9nVFknYYtdaYP4d081i2umHjAXyAi1R7Lc ESl8Xtu2YNCtrNEW5nVvZzk9/4ex8ewUd/9kD3ZY3yM3Q6f8blW/Od+UuQgdX2HFnzGO 7Yf+O7Q3/FlzuiQXRcC/mxUTfHuTmCFXhlhMWPvFbHT6hrOWIhIE8zVCg89gxJLBp1ir tqBw== X-Gm-Message-State: AC+VfDwAB5yppoZBz9kTzRrNYKpno8PfcHQyGYN9aMJz+1pmVcSzxbHD XkXkHhYSCnUYz2vCXhvxLKIlBTnUn1bA5mjCp9c= X-Google-Smtp-Source: ACHHUZ78LJbQE3Owcz9jNLolXkmcuBWmy3f7qUBhLaU/wSQ0oHGdq2KoMSWtP7BIeqFAwDQ+FXPM71TztMSW3ZJlyfQ= X-Received: by 2002:a05:6820:291:b0:54f:51f3:48b0 with SMTP id q17-20020a056820029100b0054f51f348b0mr2929920ood.7.1683718537511; Wed, 10 May 2023 04:35:37 -0700 (PDT) MIME-Version: 1.0 References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> <57aed5a4-f5e5-4a47-bf7a-69249f1d0ef1@app.fastmail.com> In-Reply-To: <57aed5a4-f5e5-4a47-bf7a-69249f1d0ef1@app.fastmail.com> Date: Wed, 10 May 2023 13:35:24 +0200 Message-ID: To: Larry Garfield 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: landers.robert@gmail.com (Robert Landers) > Regarding $field vs. $this->propName, there's a few reasons we went that = route. > > 1. It's shorter and less typing for what will be a common pattern. > 2. That makes it consistent between hook implementations. In working on = examples, I found many cases where I was adding basically the same line to = multiple hooks on the same class. Making the code easier to copy-paste see= ms like a win. > 3. It also will be helpful if hook packages are added in the future, as t= hey'll need a more "generic" way to access the backing property. (See Futu= re Scope.) Eg, "$field =3D someLogic($value)" applied to a dozen different= properties; it wouldn't work if it was "$this->specificProperty =3D someLo= gic($value)". > 4. We're used to our eyes glossing over "$this->propName", as it's so com= mon. Having a separate name to mentally scan for to determine if a propert= y is virtual or not seems like it will be helpful in practice. > 5. There's precedent for it: Kotlin has almost the same functionality as = we describe here, and uses a `field` variable in the exact same way. > > So it's mainly an ergonomics argument rather than a technical one. "Comp= ile time macro" means it translates to the same AST as if you'd used $this-= >propName. There's precedent for that. Constructor Property Promotion wor= ks basically the same way. With using a common name for say, $value, open the door for a library of common hook implementations (eventually)? Maybe something like: class User { // snip public string $fullName { get =3D> FancyLibrary\fullName(...) } // snip } I could imagine something like this would be a huge boon to PHP if it automatically bound the closure.