Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114389 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57956 invoked from network); 11 May 2021 14:34:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2021 14:34:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 72D791804CC for ; Tue, 11 May 2021 07:42:04 -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.1 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 May 2021 07:42:03 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 61AC75C004E for ; Tue, 11 May 2021 10:42:02 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 11 May 2021 10:42:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=vbSFQEyQ2NWdBJF2csGm83fuJ8pMS7lWKhD7BC8ZM rs=; b=CZ8wxDwXqR/sWV2fyk30Z/LK7pbcXlZItJ10UD4THp6YoR+Ynk/Pbw2df tdaAYwJGVrEjFbUM7h39qcbhuXo2hsmmudboTi216Dxd2UF1RfU/WnKltlF6rqxr dAAuJvg6C4vm3wGAfyT7FchQ7gaVQg3GzJK1wvasZkh9+i0xkbtGdl8u9P3DAtk/ aToV60dM2lxCKur2hsORDmBXDLYPIaTJlqV9wakjHqZasi6FvX2O0aawCKKlvgmu m+dGIBVnwALN7nSMIXCmoxhJH8RM/mkd9y/5MuQiUVZlGVjeA6/5cACEX+SEBXCk 6VLHdWV97jQ52Htrp5MGZu/CuyVmA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdehtddgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2599C3A04FE; Tue, 11 May 2021 10:42:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Mime-Version: 1.0 Message-ID: In-Reply-To: <47e8f7c7-6ae6-3744-b590-c3f39b144c46@gmail.com> References: <3f3cb374-23d8-9d26-4ea2-fe891538a7b6@gmail.com> <47e8f7c7-6ae6-3744-b590-c3f39b144c46@gmail.com> Date: Tue, 11 May 2021 09:41:41 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] New in initializers From: larry@garfieldtech.com ("Larry Garfield") On Tue, May 11, 2021, at 8:57 AM, Rowan Tommins wrote: > On 11/05/2021 14:12, Dik Takken wrote: > > So the use of "new" in initializers would require extending this bas= e > > class and call the parent constructor. Maybe forgetting to do so cou= ld > > throw, preventing initializers from silently not working. >=20 >=20 > If we managed to get that working, I wonder if we could also include a= =20 > check for uninitialized typed properties, a bit like Swift's "two-phas= e=20 > initializers". In short, make this throw an error: >=20 > class Foo extends \PHP\Base { > =C2=A0=C2=A0=C2=A0 private Logger $logger; >=20 > =C2=A0=C2=A0=C2=A0 public function __construct() { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 parent::construct(); // "E= rror: Property $logger has no default=20 > and was not initialized before calling Base constructor" > =C2=A0=C2=A0=C2=A0 } > } >=20 > This would catch bugs closer to their source, where currently there is= =20 > no error until $logger is accessed. >=20 >=20 > However, the "if" at the beginning of this message is quite a big one:= =20 > it's not obvious where to assert any of this, because the constructor = is=20 > just called as a normal method *after* the engine considers the object= =20 > to be "created". In practice, I almost always see the parent constructor called first, th= en the child constructor does its own thing. Having the language requir= e you to do it backwards in order to use a new feature would be... well,= not technically a BC break per se, but certainly invalidating what is c= urrently standard practice. If I'm following correctly, the concern is cases like this: class Point { private Logger $logger =3D new FancyLogger(); public function __construct(public int $x, public int $y) { $this->logger->log("Point made."); } } class FancyLogger { public function __construct() { $this->db =3D new DatabaseConnection(); $this->db->write('Logger start.'); } } $p1 =3D new Point(); // This writes "Logger start" then "Point made." $p2 =3D unserialize(serialize($p1)); // This writes just "Logger start."= Am I understanding that right? If so, I'm... unclear why that is any mo= re of an issue than doing it the manual way now. --Larry Garfield