Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107137 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42891 invoked from network); 16 Sep 2019 08:45:33 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Sep 2019 08:45:33 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id AE2882C88D3 for ; Sun, 15 Sep 2019 23:22:22 -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-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 ; Sun, 15 Sep 2019 23:22:21 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id 21so34515972otj.11 for ; Sun, 15 Sep 2019 23:22:21 -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=1gx4Yc1vWdkjPz6PthTizKMN5SLGDvmS2QZoqFHy0Zc=; b=cT8YSPU6U+ZLcDOllyBMHiHXU8iPTHxjJKLM1w6cGHXJPq33HbVrs1hy52SLX+SHlg RZ8DHrnAvYwRRBB4q4zRU7ZHC2pmQiHf/1no2FOzz05pt/fi/y9iEUuCu0GX6cffB4B+ jk28i3aEno9FYoIQKSYcA/GHo7ErzHTzxOvIhPVbtugI3Cj2GQfL/oj5UgCHrHWzHGuG eDM9FcwpfhOXus4wDXufUbXpkxv7jVubFCwzSk3ZICBu850H0A1/qJcdjSJcmH0ohMWd jIqtzuGw/RxFBMelk2AojxpgmYEQyrs9ihthlguf1c608Ut2bjkoZLrckJjIxinamyNV kJIQ== 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=1gx4Yc1vWdkjPz6PthTizKMN5SLGDvmS2QZoqFHy0Zc=; b=CShLoDh4nDzS14vThtIkL8Wz2XCdsJgRIO5klCPnegRgbBdrRq4lRgiTzClKUOOKhd 7CQlT51FsHCvPePFga9EHcHcrAXX5x6ljicabSDMcWnc9C2dD6aLed79obLY7Y2fJM2g j0FzGDxfk8oQQiT16IqU7VYfY+Gn1tOnSQ2K9QLxPXRq/IZjeKM44+zM7iYfCWRA4W3o 0wNgzbfIbq/b/W2blva11d/7UwpivCUYRY1nMD4EIxJLSvXpWFHd7K1POyztfTtNdokM 8lWTagTEDU8VCKnESfaz30wt2TrT7+M5r+cREtkWZROPR11rJxK222z9kwJ8R0vqYncz uN5w== X-Gm-Message-State: APjAAAWfNbmmKcmAU2AOEGuK33raZsSJ/2r50fwo7o86NlFU6X7hwZJU iQDuGXqNX09QVToalmFYfnRcRP4pYfOrKOfQay5nj2+p X-Google-Smtp-Source: APXvYqxyDLNfbmSOerivjOyrblhMxAW7A3O2UNOE8U8L6fM7Rd9adb0bK7oC5NCNGLmAHRIoOY76ZDYECHMlLOsLDCo= X-Received: by 2002:a05:6830:1d85:: with SMTP id y5mr32285935oti.214.1568614941108; Sun, 15 Sep 2019 23:22:21 -0700 (PDT) MIME-Version: 1.0 References: <18D5453E-D962-467C-A50C-52658C11BB25@pmjones.io> In-Reply-To: <18D5453E-D962-467C-A50C-52658C11BB25@pmjones.io> Date: Mon, 16 Sep 2019 08:22:10 +0200 Message-ID: To: "Paul M. Jones" Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000005ab0ab0592a5a02b" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Object Initializer From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --0000000000005ab0ab0592a5a02b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Paul, niedz., 15 wrz 2019 o 15:48 Paul M. Jones napisa=C5=82= (a): > > > > On Sep 12, 2019, at 09: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 propertie= s > > initialization in case of classes without required constructor argument= s > as > > a single expression with initializer block. > > > > https://wiki.php.net/rfc/object-initializer > > This reminds me of how Hack/HHVM would initialize object properties from > constructor parameters; I remember finding it very appealing. > > IIRC, you would provide the property signature as a constructor parameter > to trigger the initialization: > > ```php > class Foo > { > protected int $bar; > > public function __construct(protected int $bar) > { > } > > public function getBar() : int > { > return $this->bar; > } > } > > $foo =3D new Foo(1); > echo $foo->getBar(); // 1 > ``` > > Perhaps something like that is worth adopting here. > What you're describing AFAIR was called "constructor argument promotion" and this is not kind of problem current RFC tries to solve. Argument promotion looks useful for constructors, in the name of good practice constructors and methods|functions in general should not require a lot of arguments. Thank you for your feedback but I believe the suggested solution is off-topic. Thanks, Micha=C5=82 Brzuchalski --0000000000005ab0ab0592a5a02b--