Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114268 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75854 invoked from network); 4 May 2021 13:52:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 May 2021 13:52:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76DD51804DB for ; Tue, 4 May 2021 06:58:02 -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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 ; Tue, 4 May 2021 06:58:01 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id w15so9904496ljo.10 for ; Tue, 04 May 2021 06:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ihpI0DsHVTIW5cAZPjoHYHOlj9XpCDQzEziTTKu/Y+k=; b=Za9YI+kVhnUVNaGtnFbC2bkcdKRun5/PszvPFpGp1/vhqUvE4JCTGpBksMyYL04CvN 8LHSJwPmcGjGvstRR0hOOtIBwvicH8q2zgQtjH0eH8wKC5Ug0CMe5o+eEg5nuSel0XpZ nWYUmm2Cp2YmF6J/cAZD3gI8z8/KyeXRvux74kWiMU/I7PBh/CWeWJNIT0jDCVh/JPoN LPyXv4fCTfgDJupeL35wbeSwRLhq75SZV6Gsq7XD6PqisJ38T7eW+kitmNQvkjXQJm8f u4LSMvbeNCV8pQ3b96p6KdGoWzYz+0+Jc4rJhww0K7VvftmF00lz5+uSFzYP40VW0Tg8 YLqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ihpI0DsHVTIW5cAZPjoHYHOlj9XpCDQzEziTTKu/Y+k=; b=JXNyjja6H1n3/t6rje03K4B9GsVB7MCt3RIlquakWt/Cluii6inLYH+NU9XG7dZsEf 3WqqULmdmt+SaKGgTkntITky2ocopMtJxyKZ0ujt2zzbqpnfCWOz5uf82TQmmrjJnaHS dZMG9cnru6hTQfgGmHbaYEflOOIMcQrSBx+Z3RulQXjBrASyQ/CDTJD9pzxNVwVL1Acn grhQyN7gjNqUIRhay3xQZItJfCuxk54B/m4Ee+br70CmWPXwQHy6toVz2JHFUdF5hlEu PYUBAOamG9l5JUpY2LDW7DPsQ0sWmtEdWQ5GofLEuWMk6hlENM3l5pcmMO7XpLxGdt9N cRBA== X-Gm-Message-State: AOAM531MQdYq1rWfIhd9Lo6kqtLjZDxfXnIA17EdgJN6WTvFGdTF3t+B 8FM4aUaaCBgtwTqB7/EWV1ONpABHYO8s5NUPwc0= X-Google-Smtp-Source: ABdhPJywAR7l7eQLOeVvViCC8LdQdZ6O6VbOCjU57dkaJvvyKHXMb5zfWwRT8ELmoNeo+sFmlEyiLaJu5gT8RtQNRk0= X-Received: by 2002:a2e:9185:: with SMTP id f5mr13077282ljg.194.1620136677358; Tue, 04 May 2021 06:57:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab3:1102:0:0:0:0:0 with HTTP; Tue, 4 May 2021 06:57:56 -0700 (PDT) In-Reply-To: References: Date: Tue, 4 May 2021 15:57:56 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Property accessors From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2021-05-04 12:33 GMT+02:00, Nikita Popov : > 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 > Hi, In general I'm no fan of trivial getters and setters at all in OOP. I think a better solution is provided by: * readonly properties (or write-once, in the constructor) * namespace- or package-internal accessing; "internal" as an alternative to public/private Especially when getters and setters do not upheld any particular invariants or check validation. Note that namespace-internal access cannot be provided by getters and setters (though technically it's a big and hard change to PHP, AFAIK). Olle