Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114793 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34644 invoked from network); 9 Jun 2021 09:50:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2021 09:50:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1621F18053C for ; Wed, 9 Jun 2021 03:05:40 -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_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-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 ; Wed, 9 Jun 2021 03:05:39 -0700 (PDT) Received: by mail-oo1-f45.google.com with SMTP id j17-20020a0568200231b029024900620310so4492035oob.7 for ; Wed, 09 Jun 2021 03:05:39 -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=Nsdn+l7cuw0BjB6LadLmgl7Xq/VnJqVfemECa9G+FxA=; b=BtNdf/ljAt5gbUBJ7EioqJTONMdBkyZxDBQdwkzpZo94aXOrOrzZ3grEwgga6wFdki aPA6r0DxBEPm2Rln8zmh/G2X3tf6fVBXvNpQIzmkSP3WxLmxN3KCrnQtFb2LfOB3pnto tTnl3hcC76fXtYCTHfN9lYuoiM0axqLizl0w3e28drxg9o/3qv7JtI3LPmuphGEV8KWM HMbCVZdZfoGVnyQgqed/I2hAQdxaIG1KMTZLvIM/+z0No/tC5dMibJYGqGacoikqg78j xeuE2vSmfhU7sfkfvHu+/4uLPnT6UTU+cHUxazcxnfwrZM7DPykhnBWlFt4cyOJ6CAln Nlbw== 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=Nsdn+l7cuw0BjB6LadLmgl7Xq/VnJqVfemECa9G+FxA=; b=IG4kZFyl1tIuZFzzICATsWYZtMTbHklxIJZeapv1WqtzZDKULPBmyTi8hcNJa2AuQ+ zzdKlhJbWRHypjU9/U1mVIFQ5mHKBNtPxQ9H8auB2hiS/gqzrImorrA/kF3zG7AnlGat UAA5GAiHtZIthdhS3rzfNvNuWAaakpe/M9Tya9c88yaQ3LNJXRjUKL3NWMNo52XnuZiL cdYS3sJpOOhDgtzTLvbk5UQbBR6VynnzneP+zp4qVBiTnf38wmZLujC1SSPSu7KH07q9 aEIjcKAi8/JtQGVnaVVhZnmnnLVTqQNwBJCL90KhV66cBGyrb5c+WE3R4VAyFekVM9cv ajHQ== X-Gm-Message-State: AOAM531QuUYv6Ly26jdwB7tw2utF9QKwOrAX7cUMV+KlwWS6GfVrMqJs d0j67mcJaA+YDu7SJHJqpcKxE0nD08t3ViviSSQ= X-Google-Smtp-Source: ABdhPJx7f1G8mFy0RrG/A+vQz3Ow3mdEXwNIjC7rqIzBwpEx1+Ul951fJML5bmCZZ6ESkx73KCUlEiu9417ySnmYz0U= X-Received: by 2002:a4a:ea2b:: with SMTP id y11mr15340010ood.77.1623233136577; Wed, 09 Jun 2021 03:05:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 9 Jun 2021 17:05:26 +0700 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Readonly properties From: pierre.php@gmail.com (Pierre Joye) Hi Nikita, On Fri, Jun 4, 2021 at 10:19 PM Nikita Popov wrote: > > Hi internals, > > I'd like to open the discussion on readonly properties: > https://wiki.php.net/rfc/readonly_properties_v2 Very good work, thank you :) > This proposal is similar to the > https://wiki.php.net/rfc/write_once_properties RFC that has been declined > previously. One significant difference is that the new RFC limits the scope > of initializing assignments. I think a key mistake of the previous RFC was > the confusing "write-once" framing, which is both technically correct and > quite irrelevant. > > Please see the rationale section ( > https://wiki.php.net/rfc/readonly_properties_v2#rationale) for how this > proposal relates to other RFCs and alternatives. About this paragraph in https://wiki.php.net/rfc/readonly_properties_v2#rationale: " The addition of readonly properties neither precludes nor discourages the addition of asymmetric property visibility." To me this sentence is the meaning of a readonly property, not an immutable property, as in writeable once property, in constructor. This RFC is perfect given its goal but the property attribute "readonly". How would you define a property only readable from outside the scope but writeable inside the scope of its class (->status f.e.)? This is PHP and we always have our ways. That being said, the keyword "readonly" is really about what is defined as "asymmetric property visibility" in many other languages. Rust uses annotation, .net via either readonly and they use an init setter to make it immutable in v9 (public DateTime RecordedAt { get; init; }), other like java or scala relies on setting a property getters only. Given this, I wonder if it would not be easier to have actual per property getter/setter as an addition or replacement to the current (kind of horrible) get/set($name, $value). This would all cases in one shot, a more complicated shot but much more powerful. For the record, I am totally not a fan of the 'manual" get/setMyProperty ;) In any case, I would at least put a second thought on the name "readonly". ps: sorry if this question has been discussed in previous RFCs, pointers appreciated as I did not find it :) Best, -- Pierre