Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118563 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34246 invoked from network); 5 Sep 2022 09:01:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Sep 2022 09:01:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 367DB18050B for ; Mon, 5 Sep 2022 02:01:17 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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, 5 Sep 2022 02:01:13 -0700 (PDT) Received: by mail-ot1-f53.google.com with SMTP id h9-20020a9d5549000000b0063727299bb4so5751141oti.9 for ; Mon, 05 Sep 2022 02:01:13 -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:subject:date; bh=QM3AZIsXdoXQTmhTcUMGJgypLWO+30ph21VEE9PsfnI=; b=Gtl/6wCMK2Wz6QPVodU6uLIVbQrVw97m17jayAA8TZ5rLhQCHqN4IEHhTHaU80ajAl zA7nKkwruqGGb6aNCHVqUy/FLUP0guuesk1xGUOpUaywagqH6+11EAHIGQeesrrR1+vS pNYaNPbO3Ilp2SfNerQcDLouSO0iPFMorUVY470xuqXwnJYEzvBJyMp26cshQoe4YwdR zp+9oJtHvquebUbVDVjFNaTnMLyoRr0l/uWX/blSOfyPyXjGqknpUpTS7O1yxDxcfwyD Zq9PeY+wEX9OUzhmdTrxccoBJ8vVZ+rBFbYiJkMKchpqouHRT/T4CvuMNDipXjoRSCBS PUnQ== 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:subject:date; bh=QM3AZIsXdoXQTmhTcUMGJgypLWO+30ph21VEE9PsfnI=; b=v8Wlsu72gBNaQf/HwCBO/EQrm1PkpXeTpfy+BlnbXTzkJjv8i2u+f0Mp4eVhdMUXKv 94Vmclex+5fkDaqyk0pb7AcdvnvzOoP/YP/vT/LDIMKNBDV6tMVySjpOI7yOEtGfEu8g QD2cm1P8NCGiiTxT5fUuwRYonTZZDGcMzXyWkDSY7UfkyjZ03ATxhFERGdX/meYUbm6P TjYFmOD2qvfYSao6ym0ho07gWf0vgyqGif8VUBfOOGlSWitHsSsFKBtIf8YTLQnc2wEK XuAN+EPwSnTytAK1/AO907gqMEhya7pzRXmW0eTxlijnbULzFv/OICye9nTpkfPR0+Tz eenA== X-Gm-Message-State: ACgBeo3SYnaCg8h8DUnGvlnmWIgrTRxTQ2xe2HU1DNG5/1m13NixQsS1 nX5FmfuP/taa4K3qzThDJbj7KbmwYs+CLa8L0rg= X-Google-Smtp-Source: AA6agR5qB2rWP5UNaxqwkq4BYioe5tdT3iktc3gB4vY8/NLJCydCcwXmJ3PMEYJp91EiN8DdUFV0yaDjPfXDyBAJwDc= X-Received: by 2002:a05:6830:2498:b0:638:9325:3370 with SMTP id u24-20020a056830249800b0063893253370mr19604556ots.228.1662368471680; Mon, 05 Sep 2022 02:01:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 5 Sep 2022 11:01:00 +0200 Message-ID: To: Nicolas Grekas Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000003d8d0005e7ea52af" Subject: Re: Issues with readonly classes From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --0000000000003d8d0005e7ea52af Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nicolas, For 2.: static properties are useful e.g. to cache some shared state (info > extracted from reflection in my case) and I really don't see why readonly > classes should forbid static properties. Readonly is only useful for > instances, because it gives them immutability, but what's the link with > static properties? Note that this is less important than the previous poi= nt > as it's always possible to store shared global state in another class. Bu= t > still, this feels arbitrary to me. > First, I'll answer to your question about static properties, because the answer is simple: as readonly static properties are not supported ( https://wiki.php.net/rfc/readonly_properties_v2#restrictions), I had to decide what to do with static properties of readonly classes ( https://github.com/php/php-src/pull/7305#issuecomment-971381308), so Nikita and I agreed that forbidding them is the better option until we add support for static readonly properties. In my opinion, being able to set readwrite static properties for readonly classes would be very counterintuitive. But I'm also wondering about B: the RFC doesn't contain any rationale about > why this restriction exists (it says "Similarly how overriding of readonl= y > properties works", but the similarity is quite weak, readonly props don't > apply to other properties of child classes.) If there is no compelling > reason to have this limitation, it should be removed IMHO. Basically, thi= s > would mean that child classes of readonly classes wouldn't have to be > readonly themselves (but the existing properties on the parent would have > to be of course.) Regarding your main question: I understand your problem with readonly classes, and I'd be happy if we found a solution which fits your use-cases and keeps consistency for the engine at the same time. To give you more context about the inheritance related restriction in the RFC: I went with forbidding the extension of readonly classes by non-readonly ones so that the invariants of the parent (no dynamic or mutable properties are allowed) don't occasionally get violated by the child. However, I cannot think about a proper scenario now where this would cause any problems... I'm wondering if anyone could come up with one? And at last, regarding the interaction of readonly properties with __clone(): I'll definitely think more about this topic in the following weeks. Currently, it seems to me that readonly properties should be able to be reinitialized once *during* cloning, but not afterwards. Is this in line with what you want to achieve? If we once manage to add support for the "clone with" construct then readonly property reassignment(s) due to "with" arguments should also be allowed. But I'll need more time to also consider any undesirable side effects/edge cases, which could apply, should we settle on the approach described above. Regards, M=C3=A1t=C3=A9 --0000000000003d8d0005e7ea52af--