Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112319 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50081 invoked from network); 30 Nov 2020 15:46:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Nov 2020 15:46:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB4FA1804D4 for ; Mon, 30 Nov 2020 07:13:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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, 30 Nov 2020 07:13:52 -0800 (PST) Received: by mail-lf1-f53.google.com with SMTP id s27so22288626lfp.5 for ; Mon, 30 Nov 2020 07:13:52 -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=VOQMpUOL2Fzf2Y657Trn23YhicZFUJ9uVARSX8PdOKo=; b=ejRTtVLMN1/1b3fl6SH0u1TkRaUT8iFyYhybyjjtJaNkz33lOXEgeBgo+wHXi1zdOv Xg8jgK20blQeQS/66tWxAQE8InV0ZW3hrkEwWLVeG+7kZVC2Zo1qeJCGQblZYPhCVDr0 wkX2bw2XFYfOUpRp+ZbeiEiua7PLIozOFktCfI+Kb5GTB+nRrpI6PMoOFitArIEqOUH4 svUggrt7wonfLMZewGyJTtEVUtVTj3p1xL6v1MLLahMLB/I2xhUD96jVBEe9aCHsnTxE xZEdv7n4ppXdS05cUX4TzVwXs1Z8Nu6wf2tnqSbqLLxx5TLJkbX8c9Bj4lhotcm8s3/X wD4A== 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=VOQMpUOL2Fzf2Y657Trn23YhicZFUJ9uVARSX8PdOKo=; b=OHsZ5RjsYCdpiUoulX/sCYOxEN7x0w0ZLSZz+UJS5hXTFqxDzW6cdY/3SCeZQQZuwy Q2fSEp8xnqJXYSJq54D0j2Dxu6VZkl8l8KnYobkGOjWyYWug/yaH2YBFsK20a1WBFaHy V1+YqPP/UyQevOUjrH7DmxI9ewxWy1U7fDMYp+8YZFHZglvrGiY3b+C1qO1rejGpqwLd uFYj5E2TU1OkeAwuZlgozVEvdlqh3sx3eRKaiTeMK5NnHpBZH+kV6jVnYnxAAkMRNiCf bLD1klg4mU7LFyk4hTFd8UcWO+FN9jJMEUflXE4Us7cP6k6I3szd/2HqPjNF7w0el+Xp cLJA== X-Gm-Message-State: AOAM531T8qdQKx9GQFAkg6d0TDEWpdPscKU7rb4eoHsZLvHbWa7V4pdt qJSidNalvjo3MpEQhIkCnzSyExEA8ZSz7DwLLbo= X-Google-Smtp-Source: ABdhPJzNSWPl7XZ75lr0253MeCJYPu1CsQg56Fd9yBdiQ22Lb+OyvMccS/pol8wKArYv3cP3pVmAoKfKz50WGSR24XA= X-Received: by 2002:ac2:50d2:: with SMTP id h18mr2178729lfm.169.1606749231189; Mon, 30 Nov 2020 07:13:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 30 Nov 2020 16:13:34 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000002b138605b5547597" Subject: Re: [PHP-DEV] Method parameter promotion support From: nikita.ppv@gmail.com (Nikita Popov) --0000000000002b138605b5547597 Content-Type: text/plain; charset="UTF-8" On Thu, Nov 26, 2020 at 5:31 PM David Rodrigues wrote: > Hello! > > It is just an idea to discuss. PHP 8 now supports parameter promotion via > constructor. Could this idea also work for common methods? > > public function setAge(private int $age) {} > === > private int $age; > public function setAge(int $age) { $this->age = $age; } > > The only problem I can see would be the difficulty of identification of the > possible properties, since it would be necessary to check all method > signatures to know about all possible properties. > > In this case, perhaps, it would be enough to allow the promotion only if > the property already exists. > > private int $age; // Required. > public function setAge(private int $age) {} > > Just to think about whether it is possible to think of something along > these lines, but I'm still not sure if it's a good option. > Same as the others, this doesn't make much sense to me. The "private int $age" syntax is supposed to combine a property declaration and a property assignment, while here you seem to only want half of that. I think if we really want to have a short-hand syntax for this, it should be: public function setAge(int $this->age) {} However, I don't think this is actually worthwhile. Since the introduction of typed properties in PHP 7.4, I would consider getters/setters to be an anti-pattern in nearly all cases, and a potential future addition of accessors would obviate the need for them entirely. Regards, Nikita --0000000000002b138605b5547597--