Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109107 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90489 invoked from network); 17 Mar 2020 17:30:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2020 17:30:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 54853180550 for ; Tue, 17 Mar 2020 08:53:32 -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 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-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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, 17 Mar 2020 08:53:31 -0700 (PDT) Received: by mail-oi1-f174.google.com with SMTP id r7so22287709oij.0 for ; Tue, 17 Mar 2020 08:53:31 -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=nsQC94jWAm6TxBNM1IooCi9XGA2HHpFRZw2OYH4mg4k=; b=tNAhx93BBT162khPlrvHjNod+LZOoNsLNJCcaqYOzpHGm1wCj1ky8kMdYWYMoeh88K uarFwDC/UhYwRrMEosRDMURNJZqZJE71j/hcQxbom7otNXaxvRTynTBRuo4ZneNY1iwU OdieOBcJyMLvPTMcZu7JJSPMkyHqoXe9KAUv/d8tAzbl3FKTHAPq2bVUceKbRw/11vQ5 HlHbNVZfH4lRxE0S4+tI3TMxenL5rsovNHPb2sBOqeKk14oeJQ7zBlQTKECI0KTAQB1T RY+Xm2WKraS6sUeTWWnmtkiZslQwXjKu6k/bMZ4hqbobHjEEKEGQprQ7aq3ZymowwUHV DXiA== 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=nsQC94jWAm6TxBNM1IooCi9XGA2HHpFRZw2OYH4mg4k=; b=sQnkvYDi/fp+Z651w4WT3oYD6h8SJpirIyZBz7z1nUYjvrphnGa+4qFJVauN76uoVm /JE/a85FlrnklNsRprrdxoj0aSiqF52oDz7kQMh8Dpf4HSIsBD5yrFywZpNuul3kRTcO +0GJZ6syBVzi2d1Ca9DGChjEdA6fRv7gqmcOWkGLLOdr9GFtx46gHvWQA0sk7sc/KQvM /SY5LS0Qs8jL20Ho0+wRWA1gbN6lwIuqgJUaM7IqBUvCmfRUGLEJ2edysKsOed8HKKFd gT7qg+/q48zqN3CCv3C125twEkJAuJ7eUy1+FkZmtR6fGKI8fIUBXKeP0HVxPSYajzNM o+9A== X-Gm-Message-State: ANhLgQ1XNREELk+Sp33JeQKwtDFCqacihZ76L3CEgHw7X3x/kxWoJfqh yWy5f9Igj+tKiQcUe7VuMaMTFdtD19Dq/UoXKGQ= X-Google-Smtp-Source: ADFU+vtc3Ae4NogfJcbzGYN047glzs0ZuwoaulTHtFh8f6i7i764szjEanE6/ikMgZ94mYDnu4DH5HXG1HD6qhsXkZQ= X-Received: by 2002:aca:54ca:: with SMTP id i193mr4079312oib.163.1584460408999; Tue, 17 Mar 2020 08:53:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 17 Mar 2020 16:53:16 +0100 Message-ID: To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d6d25505a10eefe5" Subject: Re: [PHP-DEV] [RFC] [VOTE] Immutable/final/readonly properties From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000d6d25505a10eefe5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > I'd like to reiterate my answer then: I think your idea and my proposal > doesn't try to solve the same problem. > Like you write in the RFC: > Although actually =E2=80=9Cwrite-once=E2=80=9D properties and property ac= cessors are orthogonal to each other, it's arguable whether we still needed =E2=80=9Cwrite-once=E2=80=9D properties if we had property accessors. Both proposals relate a lot to each other: it's one or another, both cannot coexist: there is only one meaning for the "readonly" keyword once it's bound to some interpretation. > once a =E2=80=9Cwrite-once=E2=80=9D property is initialized, it can't be = changed after cloning > The solution could be to add support for either object initializers or property mutation *during* the clone operation I think this is my biggest issue: it is very common to write immutable VOs with "withers" on them (see PSR-7). Thus the RFC doesn't address the currently most common way of writing immutable VOs I fear. I would be very interested in having at least a draft of the possibilities you have in mind because I don't get the suggestion you make in the RFC right now. Having a better clue about this might remove at least part of my concerns. I think this sentence in the RFC sums up the "why" quite nicely: > The only problem with solely relying on property accessors is that they can't prevent changes in the private/protected scope (depending on visibility). In short, the RFC builds on the idea that preventing changes to private/protected scope is worth the listed limitations: > this RFC proposes to disable the property modifier in question for [untyped properties] > Another restriction of =E2=80=9Cwrite-once=E2=80=9D properties is that th= ey can't have a default value > =E2=80=9Cwrite-once=E2=80=9D properties must not override regular propert= ies While "property accessors-like" would have none of them if I'm not wrong, and would solve the "withers" use case. That's where we have a different judgment IIUC: to me, visibility-bound read-only access provides all the conceptual guarantees we need: - as class authors: "don't mess up with my state, you, userland"; - and from userland: "I trust you to know how to deal with your internal state, you, class author". From a static analysis pov, all would be plain explicit and could be verified automatically. Not internal-immutability of course. Note that I'm just arguing that the extra guarantee you look for might not be worth the downside. If there is a way to provide private-scope guaranteed immutability without the listed drawbacks, my concerns would void (thus my request for precisions about cloning.) Nicolas PS: the RFC doesn't mention anything about Reflection-based mutability. It could be worth adding something since we talked about it on the list: "ReflectionProperty::setReadOnly()" --000000000000d6d25505a10eefe5--