Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111591 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 462 invoked from network); 17 Aug 2020 18:13:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Aug 2020 18:13:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 590F5180089 for ; Mon, 17 Aug 2020 10:14:27 -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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 ; Mon, 17 Aug 2020 10:14:23 -0700 (PDT) Received: by mail-io1-f49.google.com with SMTP id s189so18411427iod.2 for ; Mon, 17 Aug 2020 10:14:23 -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=MgS5o7U1/AvMHgxPXId+9GVEUKmGKLISHKCP5cFlqgE=; b=hiM+vcs0RCqQBwC4zkidlPGBsR9BP4KAuKS/CmzTnK3NV7QNU7IqgzUMjTc7rvlKsS xW6tWfRKXl9AaMS0+gOeolAeynoi3fCEbKhbc5dpXZFRiK0IwdPOyPmVWdYpWhCW8y/q 9dQalCv94Wth8QRf9k/6O3FZ6ymDOO7gzMpSzp5fIeAIUZ2g39fVuI7UFup3PPnzrwKS fOzo37t+MrR393Frzywrzhkwh2KOihcoKK3dl4dyGdDcZUFK/6GcSkRP4mPi0dDI9qQw 94LqCTG3p9Ve7JSISYebFIRnx3Ubi+0a8EaK8UWD6Me181vsuHSBFFdKKwS+3FCx1VtM iKuA== 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=MgS5o7U1/AvMHgxPXId+9GVEUKmGKLISHKCP5cFlqgE=; b=jiV9a4XsgguPxPB3KFWL2qdNrCdeFGk/BoG2NZb4JZm3SIpYvSEEaMWT/aa3xeBKbr LvY7N99hV7nRLiu6FuIzkZvrBaHDOAqKfTo/HOygzkcSJRoD3euNphPpPZflzg91he/r HDqupQX20caOUBDLqWYfKliNuQwe36268dARreEoPnjj7c7ViKph1nMQvOE60Usm8vJ4 FODEgYRlrVcz7JqZ1zJcXzmRrn1/f3jzZe/KlXqxjUAPzcEUZKeMC7L7P+bRi3iFJ2oN YvezlTJ6uUaBtOZs8ACN6X1HkNs04oZ48NRy+UO41E2x0+RSkZsdwrciL3iB+xxpb+EF BKDA== X-Gm-Message-State: AOAM5322JJZXbVVk5NldnxNpQCzoWcgpFPQQiGW23Q6lJZQWQD9abEgp rRhjISGXbbyuo1l85ph/62qCFy/EUzFpOpuyvBo21wk5/LE= X-Google-Smtp-Source: ABdhPJw2WpB8vK5D6I6u+WYpKqWarkqOM/yIHNFU6L/7gZmbfGX8n3MDPBDRnkljvmdGr7MMgywmzH1Yf0UP6HbMS4g= X-Received: by 2002:a5d:9a86:: with SMTP id c6mr13410900iom.27.1597684461766; Mon, 17 Aug 2020 10:14:21 -0700 (PDT) MIME-Version: 1.0 References: <20200817164539.Horde.kYUsO4nuFe1V_fbKiAC6n5E@cloud.rochette.cc> In-Reply-To: <20200817164539.Horde.kYUsO4nuFe1V_fbKiAC6n5E@cloud.rochette.cc> Date: Mon, 17 Aug 2020 20:14:11 +0300 Message-ID: To: Mathieu Rochette Cc: "PHP internals (internals@lists.php.net)" Content-Type: multipart/alternative; boundary="000000000000ce8e5405ad15e634" Subject: Re: [PHP-DEV] Constructor parent property promotion From: lokrain@gmail.com (Lokrain) --000000000000ce8e5405ad15e634 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 17 Aug 2020 at 19:46, Mathieu Rochette wrote: > Hi, > > > > I=E2=80=99m writing a message here to receive feedback on a two ideas rel= ated to > class constructors before going more in details with an RFC. I hope this = is > appropriate behavior for this list > > > > With the Constructor Property Promotion accepted in PHP 8, there=E2=80=99= s a lot > less of boilerplate when writing class constructors. I=E2=80=99m suggesti= ng two > additional ways of making thing even easier and I hope, readable. > > > > First: I=E2=80=99d like to be able to automatically transfer a constructo= r > property to its parent constructor. I=E2=80=99m thinking of something lik= e that: > > > > ```php > > class MyCommand extends Command > > { > > public function __construct( > > private Connection $connection, Why do you use visibility modifier inside here? > > > parent string $name, > > ) { C# has something like this ) : base($name) > > > } > > } > > ``` > > > > This would be the equivalent of : > > > > ```php > > class MyCommand extends Command > > { > > public function __construct( > > private Connection $connection, > > string $name, > > ) { > > parent::__construct($name); > > } > > } > > ``` > > > > The second idea is to make the constructor body optional, the first examp= le > would now be: > > > > ```php > > class MyCommand extends Command > > { > > public function __construct( > > private Connection $connection, > > parent string $name, > > ) > > } > > ``` > > > > This would call the parent constructor automatically even if no "parent" > parameter are present. I could even see this enforced by linter to avoid > having logic in the constructors. > > > > If there is interest I=E2=80=99d like to try writing an rfc and implement= it. I > have not much knowledge of the php-src code but I hope this is a small > enough change that I=E2=80=99ll be able to tackle. So, at that time if so= meone is > interested in mentoring this little project I=E2=80=99d appreciate it :) > > > > > > regards, > > > > Mathieu --000000000000ce8e5405ad15e634--