Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121465 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96962 invoked from network); 25 Oct 2023 19:18:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Oct 2023 19:18:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1090E180504 for ; Wed, 25 Oct 2023 12:18: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,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-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (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 ; Wed, 25 Oct 2023 12:18:00 -0700 (PDT) Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-1d544a4a2f2so29713fac.3 for ; Wed, 25 Oct 2023 12:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698261480; x=1698866280; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lxPKHbl0YGfEJzW6AD6KORSsD8s3Grw07jxxz+hw6Y0=; b=eopun9ueg5WBP4/y/LDQSSsCGSVSEMDZF6eukmcFQVFdwuEmEqjcz94ZxXu9a8eoD6 aleYtjfqKkqNigoZCmuqN487/GNQC3AlAwc/kW13S/DHYFNXdlaWFQDmeo5JbEZwmNPP Tizjrn2oOS9fuxbB7bGSahUhhsuBXaAaE1//E40fTHpdKagX4DXR1OO6lIdEphVSGYXm EzmrTCBKioLkw35kXBmz4OiL6t+OfsP7FccUob0U7tDSxFu8JYzVTCmR3eRsCsYHLOsx DiKUu+s85D4eTd2/k0jKEZgmKgcYQ18mbYxIMOWrcHBUZ/iWk591JCeUg90Rvwzbv1/1 4z9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698261480; x=1698866280; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lxPKHbl0YGfEJzW6AD6KORSsD8s3Grw07jxxz+hw6Y0=; b=AgQMTIKESsL7hsGcq0YJ7WjCpTbvM4wVaJGeaU+obNywuM5ryQxVlzurhs+hecNy6z JvbPhSuh12JHeD2F37UtHnyb7Stphhm7PpxC0DjAtH3p8FKQ03kcBoB2wZjTxQ5L45dr y0Gh7Ib3WPW/2m+eIPaIgtL155HjpZFiTIPZqaz7MjVXFINhr0UANFirqP9Ttl3rAjSG n0DhZdFP9Esi97kDMLVQXE7XdwtwjGU4ahxw+XIj3H+Wdhfjm/9U817VOVeK1WP5qa9l n5iBLJLpEPifrFenGjJ6EQedd27HhLTLJqhpImAUAuMiQozqfNwmmaNkOOYgH/JP5/dN F+kw== X-Gm-Message-State: AOJu0Yxf8h60pBttUc2Z8VpBAqRYCEluX/3OsNBvV0MFOHRHQbp/VxFK pLMX3d8GhL65fJ5uA6ke+UNDkmvqLb7KBonulDbSWn/g22qA8lcK X-Google-Smtp-Source: AGHT+IEBdRmPOA/qwGoDafB+LXisgQ84ZzHLV1nwT52MgaUsnFUZjrJavriEJSW4IclsVmFMBtWJD6RygBnuj7wHO4g= X-Received: by 2002:a05:6870:f212:b0:1e9:e975:4418 with SMTP id t18-20020a056870f21200b001e9e9754418mr19390788oao.53.1698261479618; Wed, 25 Oct 2023 12:17:59 -0700 (PDT) MIME-Version: 1.0 References: <8835c45d-fb4d-4701-ae5c-aa0d956cdb8b@processus.org> <9261C231-B3D2-42D8-8762-45126AF19031@sakiot.com> <44a8c885-c586-4645-a1f1-b24560f4bcf7@processus.org> In-Reply-To: <44a8c885-c586-4645-a1f1-b24560f4bcf7@processus.org> Date: Wed, 25 Oct 2023 21:17:47 +0200 Message-ID: To: Pierre Cc: Saki Takamachi , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Constructor promoted property and default value From: landers.robert@gmail.com (Robert Landers) On Mon, Oct 23, 2023 at 6:22=E2=80=AFPM Pierre w= rote: > > Le 23/10/2023 =C3=A0 18:11, Saki Takamachi a =C3=A9crit : > >> If I understand your use case properly, you should be confused by prop= erties 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 =3D 'abc'; > } > > $redis_foo =3D serialize(new Foo()); > > $foo =3D 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 =3D 'abc' }` and `class Foo { public function > __construct(public string $val =3D 'abc' ) {}}` don't yield the same > behavior at the time. > > Regards, > > -- > > Pierre > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Here's a nice and simple example: https://3v4l.org/DU0tG class A { public string $default =3D 'default'; } class B { public function __construct(public string $default =3D 'default') {} } $a =3D new A(); echo "Original A: {$a->default}\n"; $b =3D new B(); echo "Original B: {$b->default}\n"; $a =3D (new ReflectionClass($a))->newInstanceWithoutConstructor(); echo "New A: {$a->default}\n"; $b =3D (new ReflectionClass($b))->newInstanceWithoutConstructor(); echo "New B: {$b->default}\n"; // crashes here Robert Landers Software Engineer Utrecht NL