Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114489 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8869 invoked from network); 16 May 2021 18:47:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2021 18:47:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4B83D1804E3 for ; Sun, 16 May 2021 11:56:47 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.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 ; Sun, 16 May 2021 11:56:46 -0700 (PDT) Received: by mail-qt1-f177.google.com with SMTP id i20so3171552qtx.4 for ; Sun, 16 May 2021 11:56:46 -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 :cc; bh=XJigrttRQucuFNcVzsOG3b+Z56yAAo6TeWME4MuvDwM=; b=AdE7tiDb6Ih6Cg+6BH4QFAYdxtok2HSukMjosDPX+tA3ChV9xuJ9WVViZ39KqBU83G xW//ior6HSpdM4UKjRmdGLipZFlV6Qq20PtEzCJPdRiT/s2zl/zM76NtmMGDDRyrS61L GvwokiEd5EIO4babQpkmouHJ82Mjlb7s/2NQ50VrOJ6LOLaweZ0QJpV1/366CYmfApHR kV28w4AVETR5srwIoC2m1VqK8KhhyRDtmF4P9Uhw7qtfHCHnq4H2QKFZYK3b8AmNFjxa rHFJhX+SJtpI7vAf7s6SvK4qxt14FhrxrE73HFoBjlRpMn0mpRIaqAAlMa5g43Esp68/ QNng== 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:cc; bh=XJigrttRQucuFNcVzsOG3b+Z56yAAo6TeWME4MuvDwM=; b=iiEhkgBxZciv2/Rq/VaCrQP0gSq6qMuPBR2GVkpGBms5RpAHqnxRThUD9newHFItoV jABttwVlda40JEvPpf/xL6R5vFiGDQSDd1PO7FqCVN/E/emf0iNA6cl5AhdekZuRt/t+ lx8o2yLpwQGZPbwZhP8zvRrJAkPzYgaSSgpE7zqA9Ori6neEQ71z0pqGlHn1V7233XiF HJ+AkLed341fnBTEag7R7mkKEG+ONtNT419+r0u6ucI1zxhICjnRI9vplCHuKv+Dw5Lr WM+x8tXMVqTvInB7NGctWGlX7Baj6wHkvLiU9LU2k0EZwffz0H8bYXfZcKJ2Ls1Rwuk4 A4eA== X-Gm-Message-State: AOAM5314W5WIS78TjbPs0bKGtxHr01OszO5dzOFsstGbFMdfYQTabznx Yxvze9bY3TaFxKTcJkF0DzLm8ZGvb/ZoXPjujeM= X-Google-Smtp-Source: ABdhPJxsezpLbuv2M2xxK0DWR51W6CC8tL8zH0DZEiZH2mq+fUnPEZVJnK730VIc/AS6EOoZcjzS9aYPVF3D2QCM0fU= X-Received: by 2002:a05:622a:183:: with SMTP id s3mr31937277qtw.115.1621191403634; Sun, 16 May 2021 11:56:43 -0700 (PDT) MIME-Version: 1.0 References: <8k-0GSw3SzLqD94K-w_7CKXwcfl7m7Zf8yqom5f1F_reALxX8HLFd_KkBYO-pQnNDaEyknpdP7KZk9NI-mr-vl-sBzcfmS8HdkgGxRoTmpo=@protonmail.com> In-Reply-To: <8k-0GSw3SzLqD94K-w_7CKXwcfl7m7Zf8yqom5f1F_reALxX8HLFd_KkBYO-pQnNDaEyknpdP7KZk9NI-mr-vl-sBzcfmS8HdkgGxRoTmpo=@protonmail.com> Date: Mon, 17 May 2021 01:56:32 +0700 Message-ID: To: Trevor Rowbotham Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="000000000000ba063b05c2770959" Subject: Re: [PHP-DEV] [RFC] Property accessors From: the.liquid.metal@gmail.com (Hendra Gunawan) --000000000000ba063b05c2770959 Content-Type: text/plain; charset="UTF-8" Hi internals, > > I'd like to present an RFC for property accessors: > > https://wiki.php.net/rfc/property_accessors Hi internals, I am new here. Thank you Nikita for this wonderful proposal. A few days ago, I sent an identical message to this thread but I am not sure it was sent properly. So I sent it back here. Sorry about this. 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 the engine. 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. --000000000000ba063b05c2770959--