Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120278 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27858 invoked from network); 15 May 2023 05:58:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 05:58:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A640180384 for ; Sun, 14 May 2023 22:58:37 -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-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 ; Sun, 14 May 2023 22:58:36 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-305ec9ee502so2143765f8f.0 for ; Sun, 14 May 2023 22:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684130315; x=1686722315; 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=VR6ggQssuzdr3SjSoegNS/aZX2BaIrhUqycV3RElHQw=; b=JPV5zXYqJW7QE0p23esCd9uzRtjMZReRASE41yXZ17eclahejcsqlNZwhIlXViiEgN hlj2zCA3Xf6iDlyhof+3e1zPQvi7yDHzACauoAPVzXmLBu3Sng0eBk+7GsErSFOPpaM6 lVMkxsZ1pbl5cNxy+R6PJVu6fN5MROp2hBBbj82dm9+wUyWL8ubUanSKMHxBo/g0TR/v L/ch9jbrozIDqHeBDEI6HFedAWkWkrgPvglGPqk36D9rdeGYDgGa4FWZRYRWyyDBMRzD TpmM46tng6HfK6dpVad43YJ37nXbzQ5+8Ej556rcQlRtKHnk5gWtolg+hiCfdQDgN2sb mE+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684130315; x=1686722315; 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=VR6ggQssuzdr3SjSoegNS/aZX2BaIrhUqycV3RElHQw=; b=RuENVn81emSvVyYMhw+7iaPNO6YOOqN7AMUkszqzWVEkLcL6K3F8oFkX7xkt28Xtsi XJXOxuuia8vCxa2RXr3cvU3R/UbSyu0s97SasbrNtHCf62UViAG9GRR5p68AlenuykUJ W4kPo0auKqR8lCMnfX0l9Faemj6IaMurTDjYk71OMlQx25PNz8YaB4FKyL2NGckCuN6O kEI15dw3Y+kcnpDMUbMvkgHJuDwqifKQNwEoG9L1x4B81plQOVi2GS0UQC2jrUepbeYj i03sVvjbuXDn3iR9ussvehxKrwkWpZgriJhSmw2lgzyr+FKxZ/5YdYq3sOQiiiSENRTK 4uVg== X-Gm-Message-State: AC+VfDzBSeq528kqQEO28PLdtepLImXh8UxTL7c/yvKuHh0FjNJjG5of jBKE85ykO5oBFyryCDI7QK1wtj9ivXY1ct2S0iFvDt/5EIFihQ== X-Google-Smtp-Source: ACHHUZ5MOo4zOIX37uxX8DsZ3I38TtTH60J3dhziYo0Ny+z+Vgee+0ONPbLMkzSsrHP6Oj/+RfttZwNdc0/EoFUGZ30= X-Received: by 2002:adf:e60e:0:b0:307:5561:5eea with SMTP id p14-20020adfe60e000000b0030755615eeamr19573074wrm.0.1684130315230; Sun, 14 May 2023 22:58:35 -0700 (PDT) MIME-Version: 1.0 References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> In-Reply-To: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> Date: Mon, 15 May 2023 12:58:23 +0700 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: the.liquid.metal@gmail.com (Hendra Gunawan) On Tue, May 9, 2023 at 4:38=E2=80=AFAM Larry Garfield wrote: > > Ilija Tovilo and I would like to offer another RFC for your consideration= . It's been a while in coming, and we've evolved the design quite a bit ju= st in the last week so if you saw an earlier draft of it in the past few mo= nths, I would encourage you to read it over again to make sure we're all on= the same page. I'm actually pretty happy with where it ended up, even if = it's not the original design. This approach eliminates several hard-to-imp= lement edge cases while still providing a lot of functionality in one packa= ge. > > https://wiki.php.net/rfc/property-hooks > > -- > Larry Garfield > larry@garfieldtech.com Hi, Larry ``` interface IFace { public string $readable { get; } public string $writeable { set; } public string $both { get; set; } } ``` How important is ```{ get; }``` statement (and friends) in the interface? Since PHP does not enforce method definition existence in caller site, this code is valid (at least at compile time): ``` interface IA { // ... } interface IB { public function doIt(IA $par1); } class CA1 implements IA { // makeIt is not part of IA public function makeIt() { echo " makeIt() is called"; } } class CA2 implements IA {} class CB implements IB { public function doit(IA $par1) { // makeIt is not enforced to be invalid $par1->makeit(); } } $a1 =3D new CA1; $a2 =3D new CA2; $b =3D new CB; $b->doIt($a1); // valid $b->doIt($a2); // invalid at runtime ``` IMO, ```{ get; }``` (and friends) only useful if there are: * definition existence enforcement or implemented asymmetric visibility * AND no default hook implementation provided. I assume that ```{ get; }``` do exist in the property accessors proposal because there is no default hook implementation. Whether there is already implemented property definition existence enforcement or not, i don't know. If yes, then all things are in the right place. If not, it feels like a half baked feature, just like the method was: the error will pop up at runtime. The only positive value is ```{ get; }``` can still be consumed by static analysis tools. ``` class CX { public function consumeIt(IFace $par) { // this statement should trigger error // produced by engine or SA tools $par->readable =3D "hello"; } } ``` Things will be different with property hooks. Without definition existence enforcement nor implemented asymmetric visibility, static analysis tools will give misconception about unlisted hooks if there is error/warning message. ``` class CX { public function consumeIt(IFace $par) { // default hook is provided by engine // any message is not relevant for this valid statement $par->readable =3D "hello"; } } ``` If there is no forward compatibility consideration, can we simplify interface definition to this one? ``` interface IFace { public string $readable; public string $writeable; public string $both; } ``` Thanks in advance.