Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118554 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30240 invoked from network); 2 Sep 2022 17:31:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2022 17:31:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D1B41804D0 for ; Fri, 2 Sep 2022 10:31:01 -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_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-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 ; Fri, 2 Sep 2022 10:31:01 -0700 (PDT) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-333a4a5d495so22755627b3.10 for ; Fri, 02 Sep 2022 10:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date; bh=B1zT3041N7cNDexMKwVUKRNBfyNWwDYcfhNhW6PesVQ=; b=Ks+HDD/WSnIEF1hkip00TuXiiq2BzLlyP6JuEWeoYLirZZbnA0JLeevIUDH8n+HLrF ENF50MqKW+P5/DTaG0rRfmXIU0COpfMUF561R6uPGIEvRK0Xb9TSs5J3MjtiQjmKtAYQ 9/E95ZKEOG+2x/xZdV82iXuXsyetvst6H14h2fiSgw5HWP4UuQoKMjEa0U3l0sz8Q6YX nl5xbhV5SkLXvn+3aNAGN8Jefg2hOxOsety6EO1m4l/3JXMTSXZ5WIY2KyQnDRlAY3w+ pXCCa7CNMEGHnYKwuKFw/QyHIch87dk/sqByDu4vUD8gFCftBJh3C76KB2NoPy8c3/dP I1sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date; bh=B1zT3041N7cNDexMKwVUKRNBfyNWwDYcfhNhW6PesVQ=; b=QmJ59c9v53tYB03ca4atLVUJa7UL3SXt3bKu4ujBmeJkkKMPQa4EOKCNmFEw04e0Vc 5YTY9k3ky0BzN95mUrUivKh7bsIbrVojYC3pI96mfRJgOgEONvv3UiM/rcpUd6HS6w3O lDbte4KzjCsGzpSVmDJmVehCvWhnNySaW6GmFz762cXwFEnOX6ggLp9I26oQryJvk6o+ w7I1AzN7JztNxlICEd64hEXG34Ysx27A7xSF8KkTfR2fnOKTSfIItGdjIBKDxTXEOLEN mg96orobptKzLMpblA5lRtnrOJ9rZHdKiOmvSRKhdcWHlhIh5o86jUkdTz5Up4pGIN76 Cd+g== X-Gm-Message-State: ACgBeo0xlRnMIRI25Sm8lmFNSMqCkJLsVO/8orek1hkvG3WlCWDk9Vj0 d0tD0wr/W5F5cSsT7JqK5cDjtbbNHqpcmYW2r4MrJYwvuO0= X-Google-Smtp-Source: AA6agR6D7iSuEKa8CmgmFxqA+WBDK4x4VfPNzH2ihDf7Ep5p6T5ZR4syipTohX9ks0Vmts1WJLqEaOAGcOM5lecJr0s= X-Received: by 2002:a0d:f445:0:b0:329:2037:c97a with SMTP id d66-20020a0df445000000b003292037c97amr28202878ywf.277.1662139860243; Fri, 02 Sep 2022 10:31:00 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 2 Sep 2022 19:30:49 +0200 Message-ID: To: PHP Internals List , =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Content-Type: multipart/alternative; boundary="000000000000efda1605e7b5172a" Subject: Issues with readonly classes From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000efda1605e7b5172a Content-Type: text/plain; charset="UTF-8" Hello everybody, hi Mate I played with readonly classes recently, to add support for them to lazy-loading proxy generation and I struggled upon what I see as serious issues. As noted in the RFC, and because the readonly flag must be set on child classes, those cannot: 1. Declare a new non-readonly property; 2. Have static properties; 3. Have dynamic properties. I figured out 1. and 2. not by reading the RFC but because I needed those capabilities in the generated inheritance proxies. 1. is the most serious one: being able to declare a non-readonly property is the only way to implement a cloneable proxy (to be allowed to do $this->realInstance = clone $this->realInstance; in __clone()). I think there are two ways to solve the use case I have: A. fix the non-cloneability of readonly props or B. allow child classes to add non-readonly properties. Because to me this is a serious restriction, A or B should ideally be in 8.2. I think A is a must-have so that might be the thing to do. 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 readonly 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, this 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.) 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 point as it's always possible to store shared global state in another class. But still, this feels arbitrary to me. For 3. I just noted the limitation to be exhaustive, but I'm really fine if dynamic properties remain forbidden on child classes. It might be seen as inconsistent with other classes, but dynamic properties don't have any purpose anyway since there is always an alternative to them. I understand there are good intentions behind these limitations (making PHP a stricter language). But here, I feel like this is detrimental to the language, by making it a minefield of kinda arbitrary dos and don'ts. At least that's what I feel here. Does that make sense to you? Should we remove the limitations I mention? Nicolas PS: About allowing readonly props to be reinitialized during cloning, I tried https://github.com/php/php-src/pull/9403 but I failed as I can't make it work. I'd appreciate any help on the topic. I'd even be happy to close if someone else would like to work on the topic. Could that be you? --000000000000efda1605e7b5172a--