Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103846 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65403 invoked from network); 25 Jan 2019 15:16:22 -0000 Received: from unknown (HELO mail-io1-f47.google.com) (209.85.166.47) by pb1.pair.com with SMTP; 25 Jan 2019 15:16:22 -0000 Received: by mail-io1-f47.google.com with SMTP id s22so7522697ioc.8 for ; Fri, 25 Jan 2019 03:54:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TTuh9qYhT0DZwd7odU63yYLyNsG3wkNVE/N7CE6p6u0=; b=Mmty5E/f/nDq1OyvHQmHotJ5TXsXtZUqs0zd5VANL011hmBye5xKGYVhOUtepj0r23 e651FZxE6HlDPClxf14y4hOKKVCmTTUrIh7mSqML1otGJnxz0xKNmZJi1Gw7MZadI675 Uxljmm6RR02/BXP49IDPVsXZ7dTUIOkiIQwjdGdStpg7Nwb5hj4V98Q/2FtgPb+U9F00 QPoSnHXq+sk58bRRwvvg+km27DNqtb8/hkEROxtSqjF1TntaVGJj7A/uXLxMkfC/gyho 2UEwrokb8V/h3K2p8Y9ifaH+kyXy72sh8gBDsDfVJ6DxLFjpuJWS0RF89oCB2fkIPPQN UtRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TTuh9qYhT0DZwd7odU63yYLyNsG3wkNVE/N7CE6p6u0=; b=qo5/5JCeWJs+HDghvC4odO4PKKrqLP+6YGHJbnt71tp7y3Jyc9EZ9LKeiJF5X+wAM+ 8ZngoVbIjY4+Q+itmT7g8LQaB6SLoGyIHGXqrVPFPJXPFp7Xj97SWplru/6eyAQADGjE 36tP08uq8BgX1c3e2jYMEq4L8YZmay76McE9/00I7YwQ8by8OdM8qZjYuDeNrRwNrdHD fAnWJa4VhLIrln5gVfF08ilhm/f5gDwM3YNzmTbMgZc1p8KsHz1Vyafo/EMzyUNo+uXC KQAQOd64nkKlDU2vdGjUZ5Y7fjwzHbhhwXV4VlvmZ4Mqxwurr0jWCWzdimG/fIvCJx0S ED1A== X-Gm-Message-State: AHQUAuZQAXj7OGh1k+RG5v4drqBzX8Nigh5/ybfdbZIYnJQgZpbhG5np oBJCbtznLOmebD+NP0rkwxHk2SWkMV/OM6Tc8Gw= X-Google-Smtp-Source: AHgI3Ibp9eSRzlYMREQppl8ufDUfDEUFyHmoKll4GgQOZXV9smDxeiQAcY5ewwz4rkyhCyeJR9lvM+kz08J7cra0VmI= X-Received: by 2002:a6b:7402:: with SMTP id s2mr1981562iog.219.1548417284579; Fri, 25 Jan 2019 03:54:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Jan 2019 11:54:33 +0000 Message-ID: To: Nikita Popov Cc: Andrey O Gromov , PHP internals Content-Type: multipart/alternative; boundary="0000000000003629b7058046fe3b" Subject: Re: [PHP-DEV] Proposal fo "Code-free constructors declaration" From: rowan.collins@gmail.com (Rowan Collins) --0000000000003629b7058046fe3b Content-Type: text/plain; charset="UTF-8" On Fri, 25 Jan 2019 at 11:05, Nikita Popov wrote: > class Point { > public int $x; > public int $y; > public int $z; > } > > // (syntax just a dummy) > $origin = new Point { x = 0, y = 0, z = 0 }; > > Where the object initialization syntax ensures that all properties that > don't have defaults are initialized. Especially now that we have typed > properties and it is feasible to have data objects with just public typed > properties, I think that this is the way to avoid ctor boilerplate, rather > than making it simpler to write that boilerplate. > The big difference here is that you are making the short-hand the responsibility of the caller, rather than the definer. I suspect there's a Venn diagram of use cases where the two features would be useful. In particular, the call-site syntax you have there would work really well for a value type, and could go with having full support for that (e.g. have the resulting object be immutable / copy-on-write); it works less well for something like dependency injection, where the properties would normally be private, and you might want to combine the short-hand with some normal constructor logic. Regards, -- Rowan Collins [IMSoP] --0000000000003629b7058046fe3b--