Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120277 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10702 invoked from network); 15 May 2023 02:21:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 02:21:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5ED7E180382 for ; Sun, 14 May 2023 19:21:10 -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-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 19:21:10 -0700 (PDT) Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-3f42a314090so13518135e9.0 for ; Sun, 14 May 2023 19:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684117268; x=1686709268; 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=qEWLFO4MvE+xD5A1ym/etCVcmWaMsbOxI/AvFsqq5OY=; b=sEcq1uWTXiQUdhGIA5Vi8cMZe/NZMTmWi9NJM20pDj218ojKGeiN5R+LC2jDepOcoe L7CKVI2b/KTXBS/3xHnVBesdhacyq0HFNXHjV+raoFfj0HB8v62GivG6eLpvcCLn86+r Il3n9lFkXhiEOv5f6iWK/5HdYMLupGTVhHuOFbObAjp8WXAHzGZr0i3D2h1FIAwDR+wn qiK1DU4g2EXHgIlzwo0p+6cL3Ctqkw4+ztXDCO6IY1Tfz2fmKQhbHkhLVgYmmSeI0Ram DVKlqM2pHHlRw+/pg8uTCtXzbXrU7nWwsY5+mH/+8PGYE6EiPDMwtY6wJtTSeWIHRSQ3 HY0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684117268; x=1686709268; 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=qEWLFO4MvE+xD5A1ym/etCVcmWaMsbOxI/AvFsqq5OY=; b=XcPOvcN0Hcf1OiuvZPkW6i+lGXi2xaIg/a0Wlcscesnk9COznmZnXZyjHJ1G/UQf53 jIL01NS/8yXpAtn8g2ognU27RPYSgyJ95jU348fsQnsESPah3Jf6YRgNqinNMaaBAIRq L8mnPq5UiWga6eljhMO9ixBG5Pg0848NU6/Cektp/1vDO1PDmRPwAeVq1VnMibZVqgou OGw8+zP8WBIL74BE/qqwJqdv+LoOOR4n3sPtI65lb395maqHS1Kk0gkCGkDhT2SjLNsh VO8w9DNH+o+9nuOUBV5hXkzlTujQIjfknGP+UUOYFDeNy+24BSH6aSh8zlfjciPOHi5L e7Ng== X-Gm-Message-State: AC+VfDy3Ji8T2kauQQz6UFKzzj2CvVIaTHspvEjcQEPpGKL8RqY3FDy5 gNcZTTp8vA4d3YiVHh2BwiGXbdIsGtzjTtfGVIf/I4xkrSWvHw== X-Google-Smtp-Source: ACHHUZ629Pm/OxZz/eNFkImTDwCv7b4xak2mN0Gat6Z2SAjvrtcfWgjsMkLH4aW078NuzgW6ZP4kkqAHIycK+L3RNxU= X-Received: by 2002:a5d:5266:0:b0:306:2720:b00d with SMTP id l6-20020a5d5266000000b003062720b00dmr19954135wrc.7.1684117268222; Sun, 14 May 2023 19:21:08 -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 09:20:56 +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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hi Larry. Suppose that I just want to cache once and freeze, and I don't want to create additional hidden property. Please make a judgement on the validity of this syntax: ``` public string $prop1 { get =3D> $field ??=3D $this->heavyTask($this->propx, $prop->y); set =3D> null; } ``` Explanation: * Since the ```get``` hook uses ```$field```, the engine will create a backing store value with name ```$prop1```, and will be filled at the first call only. The later call will use the already stored value. * Since no new value is assigned to ```$field``` in the ```set``` hook, the value stored in ```$prop1``` is still the same as before. * Since any return statement will be discharged in ```set``` hook, the assignment chaining is safe to use and the value which is transferred is alway the rightmost value (not the value returned by the ```set``` hook). ``` $varx =3D $obj->prop1 =3D "hello"; // $varx value is "hello", and $obj->prop1 value is unchanged ``` But, this statement below is NOT ALWAYS correct for "cache once and freeze"= : ``` public string $prop1 { set =3D> $field ??=3D $this->heavyTask($this->propx, $prop->y); } ``` Explanation: * Since default ```get``` hook can be called before ```set``` hook, backing store value with name ```$prop1``` will still be empty. * Otherwise, I have to duplicate the body of the ```set``` hook into ```get``` hook to prevent an emptiness backing store. Please give a comment. Thanks.