Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121445 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34477 invoked from network); 23 Oct 2023 15:27:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2023 15:27:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 213C01804BC for ; Mon, 23 Oct 2023 08:27:10 -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.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 192.99.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mail.processus.org (ns563681.ip-192-99-44.net [192.99.44.131]) (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, 23 Oct 2023 08:27:09 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------GcN6CrP7Mj7v4e5TvG0hH5WK" Authentication-Results: mail.processus.org; auth=pass smtp.mailfrom=pierre-php@processus.org Message-ID: <91a22e31-a073-4bdb-b78f-48dd70567a37@processus.org> Date: Mon, 23 Oct 2023 17:27:05 +0200 MIME-Version: 1.0 Content-Language: en-US To: Larry Garfield , php internals References: <5be74be4-972f-4eae-ae46-6d92587ccc7f@processus.org> <78a8a19a-2e00-4437-9c3a-dc069db77426@app.fastmail.com> In-Reply-To: <78a8a19a-2e00-4437-9c3a-dc069db77426@app.fastmail.com> X-Spamd-Bar: / Subject: Re: [PHP-DEV] Constructor promoted property and default value From: pierre-php@processus.org (Pierre) --------------GcN6CrP7Mj7v4e5TvG0hH5WK Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 23/10/2023 à 17:16, Larry Garfield a écrit : > Where this becomes a problem is readonly properties, since those are not allowed to have default values. (That would make them constants with worse performance.) A solution would need to be able to detect that the parent::__construct() isn't called, and then call it anyway, or at least partially call it. Unfortunately, I can think of many cases where such a call would result in unexpected behavior. > > It might be possible to resolve, but it's definitely not simple, and it could easily lead to weird behavior. > > --Larry Garfield Thanks for the explanation ! I see, there is no easy answer, yet current state is, in my opinion, unintuitive for developers, and eventually unsatisfying when falling in this trap. That's sad that readonly properties make this not trivial. Maybe some kind of object construct-post-hook could detect those case and affect variables with default values ? I don't know enough PHP internals to give a rational answer to this problem through... Regards, -- Pierre --------------GcN6CrP7Mj7v4e5TvG0hH5WK--