Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118382 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60435 invoked from network); 8 Aug 2022 06:13:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Aug 2022 06:13:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7288D1804A9 for ; Mon, 8 Aug 2022 01:15:06 -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_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-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 ; Mon, 8 Aug 2022 01:15:03 -0700 (PDT) Received: by mail-yb1-f177.google.com with SMTP id y127so12473658yby.8 for ; Mon, 08 Aug 2022 01:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=6iflXLKqoaSPwHJsXa1ZzH/b1Idle1Ukul68ECCK5js=; b=ex51AVbJ/jjFUYPjAN2J02X226vUYP3TkcwSGv26C+oB5EIR7P8M8NzPuSoG2gm/qm MGpbI8cw/WjJ97eE46Nip4vig1bkICAeqUSqU0Q98/GMej+gM2hgqunlboZso8paXGVW sGFfIgf0Fag9AmtBTe3EWIUyv3XaOQ4aux6TU+WuM+cE/2QjI5s2AwFCAlAtrOab7b4s W3JyCWMzEzMsMK1Y3UJoV5EDdpy2RmeIci51VsWpNdrNpiSgr+ARaDVWNEdBuzFTL0ld N9mRGKKDRo+lHEnhE9CBP+Y4l6+k4U0IhYKwivDfA7Y7vlluv3BBIW8B0rMiQrVDvh/f zNfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=6iflXLKqoaSPwHJsXa1ZzH/b1Idle1Ukul68ECCK5js=; b=XRz2uhba8fjL9RP71ltTTolnV3hyPWO8YIR9PciDjomAQFPk5d1RXdud7ukH0RIk29 w5L8wV4rh1/iQ9CnVlK64UDuCYDuPK9RlhD91/t04OvzcFLm7xiGxwiYbj7grD23MfZG HNvJvBo58RkEZbrNSoXTjS/XpEem5a3A+SEpxOy/gUZGbkx7JOlnXz8coJuGBNef8DrS +QqtIJxiKe/uSibkkGQUI8YiQFxvExrLqQjIwmIMKNQsXfYJwZT+PJg9M1HPSJ8t3DuI ixF32bYtU1ZDCaSstUo8aGpM7nIi52a+DaMWB++L5/s6aRp3ob1+aA8lzpPlKhwvEDcr Iy/Q== X-Gm-Message-State: ACgBeo3URDJTmQNz7Jp9ufv8LzdDt0rSBtLtg4EWYL5LBoucDj0oHAJf cqbr1YczLjCUJg3xHEQQ5t0Daa/Eg8gK2RwYGrDLsDsTn48= X-Google-Smtp-Source: AA6agR7ozC0PT6x0wzGqzhOS2Gsex6XbZhgc1ViajxrQOCEk5+E6NP1S/ipVyFxIrAc5RAprmZlWdfjYyQcrH7Aczpc= X-Received: by 2002:a05:6902:1103:b0:67b:e5e:1eff with SMTP id o3-20020a056902110300b0067b0e5e1effmr14306584ybu.502.1659946502370; Mon, 08 Aug 2022 01:15:02 -0700 (PDT) MIME-Version: 1.0 References: <640e0f95-de30-4c53-48e8-818fdf408112@heigl.org> In-Reply-To: Date: Mon, 8 Aug 2022 10:14:50 +0200 Message-ID: To: Andreas Heigl Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000009eb8c805e5b669c5" Subject: Re: [PHP-DEV] [RFC] Asymmetric visibility From: ocramius@gmail.com (Marco Pivetta) --0000000000009eb8c805e5b669c5 Content-Type: text/plain; charset="UTF-8" Heyo Andreas, Casper, On Mon, 8 Aug 2022 at 10:03, Andreas Heigl wrote: > Hey Casper. > > On 08.08.22 09:54, Casper Langemeijer wrote: > > Hi all, > > > > In the discussion I sometimes see the terminology 'readonly' and > 'writable' being used. This is confusing because when the property is an > object that itself is mutable, there is nothing read-only about it. > > > > The terminology in the RFC seems right to me, and overall it seems solid. > > > > However, I'm not convinced this RFC is solving a real issue. I could not > find any reasoning in the RFC, except that Swift has a very similar > language feature. > > > > To me it solves the topic of making a property readable but not > writeable from the public while still allowing it to be written to > within the private or protected context. > > So enforcing usage of a public setter-metbhod but not having to use a > getter. > > Soemthing like this > > final class Foo > { > public private(set) string $username; > > public function changeUsernameTo(string $newUsername): self > { > if (! newUsernameIsUnique($newUsername) { > throw new RuntimeException('The username is not unique'); > } > $this->username = $newUsername; > > return $this; > } > } > > > readonly only solves that for immutable properties but there currently > is no way of solving that for mutable properties. > Similar question as Casper here: I use `readonly` properties aggressively, and I try to make the state as immutable as possible. In the **extremely** rare cases where `public get` and `private set` are needed, I rely on traditional getters and setters, which are becoming extremely situational anyway, and still work perfectly fine. If that doesn't work, then PHPStan/Psalm allow declaring `@private`, `@internal`, `@phpstan-internal` or similar mechanisms to restrict scope access. `qossmic/deptrac` also works wonders here, compared to PHP. In fact, I'm writing so few getters and setters these days, that I don't see why I'd need getter and setter semantics to creep into the language, especially mutable ones, not even with the reflection improvements. As for `readonly`, the reason we sometimes **cannot** use `readonly` is because current `clone` semantics can't work around `readonly` rules (discussed in the `readonly` RFC): https://3v4l.org/og8bn If we solved that, I think `private(set)` would become even more situational, if not completely unnecessary. Another puzzling area in this RFC is reference support: let's take the occasion to disallow references completely on asymmetric access, perhaps? It would be nice to see references gone for good. No need to pollute the engine for the edge case of `ArrayAccess` and similar APIs :P Marco Pivetta https://twitter.com/Ocramius https://ocramius.github.io/ --0000000000009eb8c805e5b669c5--