Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114298 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63992 invoked from network); 8 May 2021 01:01:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 May 2021 01:01:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2034C1804C8 for ; Fri, 7 May 2021 18:08: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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 May 2021 18:08:36 -0700 (PDT) Received: by mail-qk1-f177.google.com with SMTP id 197so10384249qkl.12 for ; Fri, 07 May 2021 18:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=GvDoOx2GdK72zbcX+v7Q7ccWTSM2ykhqN7CR0ICy09s=; b=YL+z6F2xZKn+xhs5QZnlLxnjQzvabPH3qD3ExswG1PVhbWv0m9iVwAYFBdAXng235R 8wepFZ2E0AcTjnooceeRfTDoJVMZo28qiga2f3WqO7sB6J+Kl8SNrKPZLFpgft5CM8Wt VO71nCz+BIfD4FhC3R/LyveN6TJ+nVHxqM2EHozxFjOgb3LFH9PLlCO81AiWmXt5yxt3 sY2ewjQ0MIOErU1kTfuSWk9w9ttYtAzBhokxX77NT3Kw/8i7LhInlRlUiDIx4DN9LcyB EykqP/AYZ4A9EdMLPJtjP1lDH6rMG+vYY2PpOuB3FcSiU8VRV5tGPjfn4tfm2XwDsoZK lsHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=GvDoOx2GdK72zbcX+v7Q7ccWTSM2ykhqN7CR0ICy09s=; b=TgXI1GosHlAEYWLAMwppBc0CZAJUafape6L+1CPZHM+2XTk/eAn0l17HObYZFUNIC+ UksYEJzYXmG5HiqGE8etmcUyPSmaOIFvMe0ogepE4fj3LtbLjBqT3Bpp4ssTTU0a4PQJ nT+tvjBHAX5tZgzn/aOVzghRHP81SzSC6bzjSDXBgSOQF1gIqqxJfD3C8zDmfN/AtRrX xoMVumZ1+/kbiu+TCTQjJrycvly6ShCxaP+6jJiFrbSBGTjGME0M9VjajWdXY7mE2Yns Wvquj6nILewKGe4ZmplEfm8WBeGwKpfjX/Cx/dDon7/XZuZXCFc3mpa5+uWxYaccXp8H 2J9g== X-Gm-Message-State: AOAM531OIdv0fukki7qSBRaEJW9tmez1TMHWfZJRJU39z6KTzPF8kZ0v MwThL2yfEnXjpokTP7RC7sSj3V9lTyXDjo6LRzdu76mtdG/ycQ== X-Google-Smtp-Source: ABdhPJyUf1uHPN2gWP51McEXWR21cwIjU5ECf27TMeiZmmu9oNp52DUqmgnmzHMzDe3bDAacGEqXABdmgnXIDsoDngU= X-Received: by 2002:a05:620a:146c:: with SMTP id j12mr12858761qkl.384.1620436113018; Fri, 07 May 2021 18:08:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 8 May 2021 08:08:22 +0700 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="000000000000e5d3a105c1c72e48" Subject: Re: [PHP-DEV] [RFC] Property accessors From: the.liquid.metal@gmail.com (Hendra Gunawan) --000000000000e5d3a105c1c72e48 Content-Type: text/plain; charset="UTF-8" Hi internals, I am new here. Let me make a suggestion for this one of mostly asked feature: class MyOldOrdinaryObject { public string $prop1 { get use getProp1; set use setProp1; } public string $prop2 { get use prefixProp2; set use prop2Sufix; } // pre existing methods // same function signature with corresponding accessor // method name is irrelevant public function getProp1(): string {/* ... */} public function setProp1(string $val): void {/* ... */} public function prefixProp2(): string {/* ... */} public function prop2Sufix(string $val): void {/* ... */} } This way: * without forcing them to use the new ones, users can choose whether to use old ones or new ones. * code duplication can be prevented, if we decided to preserve the old ones. * the accessors are more tidy and readable, if we decided to move out all multiline accessors. As far as I understand, the difference between "set" and "guard" is: with "set", we have freedom and responsibility to allocate a space. Additionally, we have to choose whether to use "set" or "guard", not both. It is a sad decision that "guard" has to be eliminated to reduce complexity. In my opinion, it is valuable that we can write code more concise than before: class MyOldOrdinaryObject { public string $prop1 { get; guard use commonGuard; } public string $prop2 { get; guard use commonGuard; } // Assuming that prop1 & prop2 have the same validity rules. // The visibility is private in order to prevent users accessing it. // Due to loss of space allocation and difference of function signature, // this method cannot be used in concert with "set". private function commonGuard(): void {/* ... */} } With this capability, the complex accessor in constructor problem can be solved: class MyValueObject { public function __construct( public string $prop1 { get; private guard use guard1; } public string $prop2 { get; private guard use guard2; } public string $prop3 { get; private guard use commonGuard; } public string $prop4 { get; private guard use commonGuard; } ){} private function guard1(): void {/* ... */} private function guard2(): void {/* ... */} private function commonGuard(): void {/* ... */} } I hope that "guard" can be included again. I don't understand the internals of PHP VM. I think the mechanism of this is compiler assisted copy-paste (same as traits), but only the function body and the visibility is overridden based on accessors definition. Regards, Hendra Gunawan. On Sat, May 8, 2021 at 5:16 AM Larry Garfield wrote: > On Tue, May 4, 2021, at 5:33 AM, Nikita Popov wrote: > > Hi internals, > > > > I'd like to present an RFC for property accessors: > > https://wiki.php.net/rfc/property_accessors > > > > Property accessors are like __get() and __set(), but for a single > property. > > They also support read-only properties and properties with asymmetric > > visibility (public read, private write) as a side-effect. > > > > The proposal is modeled after C#-style accessors (also used by Swift), > and > > syntactically similar to the previous > > https://wiki.php.net/rfc/propertygetsetsyntax-v1.2 proposal. > > > > While I put a lot of effort into both the proposal and the > implementation, > > I've grown increasingly uncertain that this is the right direction for us > > to take. The proposal turned out to be significantly more complex than I > > originally anticipated (despite reducing the scope to only "get" and > "set" > > accessors), and I'm sure there are some interactions I still haven't > > accounted for. I'm not convinced the value justifies the complexity. > > > > So, while I'm putting this up for discussion, it may be that I will not > > pursue landing it. I think a lot of the practical value of this accessors > > proposal would be captured by support for read-only (and/or > private-write) > > properties. This has been discussed (and declined) in the past, but > > probably should be revisited. > > > > Regards, > > Nikita > > Another question: I skimmed through the PR and its tests, and I didn't see > any tests around attributes. > > How do you envision attributes interacting with accessor-using > properties? I suppose there's no change for implicit accessors, but what > happens for explicit accessors? > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000e5d3a105c1c72e48--