Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121450 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42972 invoked from network); 23 Oct 2023 16:22:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2023 16:22:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3933E1804D0 for ; Mon, 23 Oct 2023 09:22:49 -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,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)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 23 Oct 2023 09:22:48 -0700 (PDT) Message-ID: <44a8c885-c586-4645-a1f1-b24560f4bcf7@processus.org> Authentication-Results: mail.processus.org; auth=pass smtp.mailfrom=pierre-php@processus.org Date: Mon, 23 Oct 2023 18:22:45 +0200 MIME-Version: 1.0 Content-Language: fr-FR, en-US To: Saki Takamachi Cc: PHP internals References: <8835c45d-fb4d-4701-ae5c-aa0d956cdb8b@processus.org> <9261C231-B3D2-42D8-8762-45126AF19031@sakiot.com> In-Reply-To: <9261C231-B3D2-42D8-8762-45126AF19031@sakiot.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Subject: Re: [PHP-DEV] Constructor promoted property and default value From: pierre-php@processus.org (Pierre) Le 23/10/2023 à 18:11, Saki Takamachi a écrit : >> If I understand your use case properly, you should be confused by properties with default values that are not constructor-promoted as well ? Am I wrong ? In this case, your problem is not with promoted properties ? > If we specify it the way you say, the initial values ​​of the constructor arguments will be available even when the constructor is not called. > > Such behavior felt a little counterintuitive. Which then would simply be the same behavior as properties when not promoted but declared in the class body instead: ```php class Foo {     public $val = 'abc'; } $redis_foo = serialize(new Foo()); $foo = unserialize($redis_foo); var_dump($foo->val); // string(3) "abc" ``` Right ? What's the most disturbing in my opinion is that: `class Foo { public string $val = 'abc' }` and `class Foo { public function __construct(public string $val = 'abc' ) {}}` don't yield the same behavior at the time. Regards, -- Pierre