Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109571 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15587 invoked from network); 8 Apr 2020 15:50:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Apr 2020 15:50:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBFD61804B7 for ; Wed, 8 Apr 2020 07:18:48 -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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, 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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 ; Wed, 8 Apr 2020 07:18:48 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id b1so7823168ljp.3 for ; Wed, 08 Apr 2020 07:18:48 -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=fVZmLQz35Ow1RSOer3Q5mkN8crZiiS+N6rEtXwrjoLI=; b=Td8CCg7AciLrU34jHvOixZFR4o6QYw57dIonwkheLDspNp5+0zISuHOKyxgD+bHHsF mlN4FGYimfso46rKjgYtWTYqR768SV8jPajX729OF5YFWyKk8P8J7jf9NbduYUAfjo/i 2O0XzS2grart7oZoGXyM2QqcIQLn79aTKV3lZBKBif7fxi4eUVNar5TQj9WFIcfs5rTm NLqmL/dbQo0iRo3vE79wgCGoSZ+anQKBqEleKDe/x3VO3+bSZVZKZjsyIBGFNdPpkTML Bh2nI1Ln+0dPtWO2HAL4GCHwHsTq2iexsfQJrncP9aFELPFgbrKBTbtamWF7Yqoaygl4 1EjQ== 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=fVZmLQz35Ow1RSOer3Q5mkN8crZiiS+N6rEtXwrjoLI=; b=LnJDbpukMM2OQ5p7hxaCEa33iN1BVf2banKjJF0P1z+OAzm5nc52B0QfeqkjXpih2V TQnsmKP6GqOltAeXvIL64ujLoLR6090XVa8uE4K91Dh/WgC6FQvFBekz2SwMkVh2A9Xp O5lKZumfHDIpIpgubgGj0cGRLGFCidXL6dz02Xv77iEKrJgdJIBkIdulBUL0XDqJ1XVx 1NJIOR2pm6/3yBHBH3jsygJo9UgTG5D9xltCvM2XxW1yy9AvCa3JkYUu1l7WOcUxD53F 9k97XpUXi/SCewkb90gfBmVOWcFj2htCupnqObKZVvp1U8E9rizHXkJg5Eyhu1v69JC0 g7uw== X-Gm-Message-State: AGi0PuYfLg3J4Ebb3+6B/UfC9AM4+rJqiLkvoZy0JS9ofUUOD+HNrFP2 21PzODSXKSTGzuuRBB1AzJc+1FkmIbK7E4t0f/s= X-Google-Smtp-Source: APiQypKELLmLuHsB6b9frWeIf3tZQzwzXztLacPc7441WUsydB/8OhUgYrmyKh45xnlwf1LS5EDb7UnnraeYuVPRK24= X-Received: by 2002:a2e:7a18:: with SMTP id v24mr5198611ljc.34.1586355524959; Wed, 08 Apr 2020 07:18:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 8 Apr 2020 16:18:28 +0200 Message-ID: To: Nicolas Grekas Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008d854305a2c82ded" Subject: Re: [PHP-DEV] [RFC] Constructor Property Promotion From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008d854305a2c82ded Content-Type: text/plain; charset="UTF-8" On Wed, Apr 8, 2020 at 1:56 PM Nicolas Grekas wrote: > > I would like to submit the following RFC for your consideration: >> https://wiki.php.net/rfc/constructor_promotion >> > > I love it :) > > Just one question: > Shouldn't default values be copied on the signature? That would be > expected for me. > (and that would make the properties still initialized when child classes > don't call the parent constructor for whatever reasons.) > > class Point { > public function __construct( > public float $x = 0.0, > > <==> > > class Point { > public float $x = 0.0; > > public function __construct( > float $x = 0.0, > > Nicolas > Some reasons why the default value is not duplicated into the property are discussed in https://wiki.php.net/rfc/constructor_promotion#desugaring. It's primarily about forward-compatibility concerns. But apart from that, I strongly believe that you should not, ever, specify a default value on a property that is initialized in the constructor. You can have a default, or you can have explicit initialization in the constructor -- both together do not make sense. Regards, Nikita --0000000000008d854305a2c82ded--