Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:107078
Return-Path: <matthewmatthew@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 24848 invoked from network); 13 Sep 2019 15:47:53 -0000
Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12)
  by pb1.pair.com with SMTP; 13 Sep 2019 15:47:53 -0000
Received: from php-smtp3.php.net (localhost [127.0.0.1])
	by php-smtp3.php.net (Postfix) with ESMTP id 826AF2D2062
	for <internals@lists.php.net>; Fri, 13 Sep 2019 06:24:02 -0700 (PDT)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net
X-Spam-Level: 
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
	SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2
X-Spam-ASN: AS3215 2.6.0.0/16
X-Spam-Virus: No
Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by php-smtp3.php.net (Postfix) with ESMTPS
	for <internals@lists.php.net>; Fri, 13 Sep 2019 06:23:57 -0700 (PDT)
Received: by mail-yb1-xb2f.google.com with SMTP id t5so9899910ybt.4
        for <internals@lists.php.net>; Fri, 13 Sep 2019 06:23:57 -0700 (PDT)
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=yGBW5UvVh4poAP0J/sjIROFJZaW0PFhTueVVKR7BKB8=;
        b=RhpiTkpMNPmVw2RR1iNL/s+7hsp6rlwSmBAbRIsFP+JRagOnVxtdS7gwB/pO1qXxuN
         WDcEx7HNE1QYwF5fJdauN3Jza2rin4b/XYxTmI/FQkYar55Oj4YDTUZL8arVX1wCWQjI
         043IwIL8gV8oACKQAf3/r96x6qzMYaW7DpcUmK0EuE8xvbywRpULdZ66bCpDy1bycVQK
         GdELuNRHK+h5kOCLsr5IF0BnK7iUjmUDdWmk1+pJFK9yr3PchD4ObGv3GkeI/DsgJHGj
         3PwsuOqXEu+XabkQmU9UYzcYR8sjlKApQvZQawUWTVsif3r46DKs/3efyfYz0a3vj/jI
         rQ6g==
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=yGBW5UvVh4poAP0J/sjIROFJZaW0PFhTueVVKR7BKB8=;
        b=KeXKZyfGh4m6oI4E0GJHqGk2gDyTaOyz96inKcqmhTlpLN/d5L3iyA4SkYFsSVFyOM
         /+Ae37xZY4wvpQR+f7clOsdDPduNpCrRSBRhxVIiuqxBt1Xx/1k6tmE+o4ROwqB1FNGr
         zEhjyTgcITkmZvbBva3CfGyrBlrMnddXgz4JWjlt9eyOpjswK16fZo00Wu2AJowQiLjd
         1if2ELYvNzn7qXyGcwn0GoWD3f7yprDyezdr/sB8pna9OZaZbmKRPGPhmJTON3EIUZFu
         V0acuWUSXOYaNzlNM+LVVQ2oe4inT6nUP1Uwr3TZXaAL50w1xEYPJmI1CEXNfpGMH72+
         GR+g==
X-Gm-Message-State: APjAAAVjJmtgm2Y/BpzpP8qlgQ1/hLupXxjpeALzbLuVsfIvc2h/xvSK
	tgk7cIacYKoh80fqbN/AW+eXOhV6gKufcytWG1I=
X-Google-Smtp-Source: APXvYqwk0CZA/omXN1EZnbnanDRg97k2a3pzY7OuhN1sk4fCcJnxyVdbpTbjCtlR6HH++bLocKEzKXHWn1OBxjFh3A8=
X-Received: by 2002:a25:942:: with SMTP id u2mr206032ybm.369.1568381037228;
 Fri, 13 Sep 2019 06:23:57 -0700 (PDT)
MIME-Version: 1.0
References: <CABdc3Wpit02=BqvVE85ciw9qo3UYc2LBatOy23yFk5z+quZ2rw@mail.gmail.com>
In-Reply-To: <CABdc3Wpit02=BqvVE85ciw9qo3UYc2LBatOy23yFk5z+quZ2rw@mail.gmail.com>
Date: Fri, 13 Sep 2019 09:23:45 -0400
Message-ID: <CAKuGYLT7sGn43yXAoYe9fxA70hL9Wrp+P1kDWpUoA--GeR4KnQ@mail.gmail.com>
To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= <michal.brzuchalski@gmail.com>
Cc: PHP Internals List <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="00000000000098b89305926f2a84"
X-Envelope-From: <matthewmatthew@gmail.com>
Subject: Re: [PHP-DEV] [RFC] Object Initializer
From: matthewmatthew@gmail.com (Matthew Brown)

--00000000000098b89305926f2a84
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Though this is truly a stylistic complaint, I think it will lead to
harder-to-analyse code.

Currently I have a static analysis tool that can verify (in 99% of cases)
whether all properties of a class have been initialised in the constructor.
This check is even more important in PHP 7.4, where use of a property
without instantiation is a fatal error.

Figuring out which properties have been instantiated in a constructor is
non-trivial, and it's only efficient to do it once per class.

If we adopt this into the language and people use both __construct and
object initializers for a given class, analysis would become much more
tricky.

In order to find the error in this:

abstract class A {
  public string $s;
  public int $t;
}

class B extends A {
  public bool $u;

  public function __construct() {
    $this->s =3D "hello";
  }
}

$b =3D new C {
  u =3D true
};

The analyzer needs to understand that the initialisation of B left a
property uninitialised - it warns about it in B's constructor (
https://psalm.dev/r/0e8e40fefc) but I worry that people will start to
dismiss those warnings as false-positives if this pattern becomes popular.

Best wishes,

Matt




On Thu, 12 Sep 2019 at 10:00, Micha=C5=82 Brzuchalski <
michal.brzuchalski@gmail.com> wrote:

> Hi internals,
>
> I'd like to open discussion about RFC: Object Initializer.
>
> This proposal reduces boilerplate of object instantiation and properties
> initialization in case of classes without required constructor arguments =
as
> a single expression with initializer block.
>
> https://wiki.php.net/rfc/object-initializer
>
> I appreciate any feedback you all can provide.
>
> Thanks,
> --
> Micha=C5=82 Brzuchalski
> brzuchal@php.net
>

--00000000000098b89305926f2a84--