Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112127 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78424 invoked from network); 27 Oct 2020 07:17:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Oct 2020 07:17:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7CB2B180508 for ; Mon, 26 Oct 2020 23:35:53 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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, 26 Oct 2020 23:35:52 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id h12so287587qtu.1 for ; Mon, 26 Oct 2020 23:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=cJDghymDWqV/vpfQ2UOcaWtuQUP8IYSJPXW3j5PlbxI=; b=BMr4arv2O43chfqXv+O5IK8FVwb2YVz4iAE4MRV48NjjKswyQIOG/im9XtSOGs53Xu OlSQHSnnh1BkZsIzr4pwcr7/qV1+AG832G6ovoCLii7OYZ7K9JA9RheuZ3O1r/JUd4JP TJZr6kkN179dVkuGhl59DmuFCI1CMlxD24gD87j/9Q0EoHt7nlIhWW+ivpB9qm1vJWY6 +aTrNsOYdoPQxCV5TxsgJllgelCl5rFDcEANJm/dmx7Mr7JNw1u5xvjrEMfhXH8LJKPX ndobm6jXqMS5DOn4mRtqSL3W6EeoFrqLGGQb0oGX6zQBaUA2CU6M2LPKGLUVt/uQ4YFP zbzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=cJDghymDWqV/vpfQ2UOcaWtuQUP8IYSJPXW3j5PlbxI=; b=TBG/TxtCl0Avp2RurRgAMiYjhvvx9uVo6B7CqVMd12BBUMNy5quO1z2xQh+L1o3R++ k6WA1kU1o3Xor7H7Y+YMVsTqFQb5bC0QTD+I4SZkFczClnHKKvLXAIeGC2C5HmtEC5he VJOXV7I0mh1fKnrrx6lUam/8taMuFkmluo+B4mzNodw87T2+hxRc803tZ82W5yJGp3jN WYb6LNR2W+GOLqJUno9XSrTPs4EdT8cUKkSMOCTJY7lNOw+jsb90Io6joU1zyKI7snZA 9oSjbJA2BPG+z0My7BsdigY5mEU9OPyEpQ4murhnXt9FThDVXy0joHWYr1QU9uNkHN1S sM4g== X-Gm-Message-State: AOAM533sC+VRgVbjMhyIocMFza0lVwIFL1DW/2srNUkzQiYgn1pfRBKB H9lwHyyZ/H7/fknHBFeC2lvyYD4MZnG6FQ== X-Google-Smtp-Source: ABdhPJyO0eX34eT0bhG3oe9Eybw5uN9+LXaXfdsQPEiXw1Moch06eL3ZYOAiLhe3t+pi9zQIf7s91w== X-Received: by 2002:aed:3bc1:: with SMTP id s1mr736063qte.6.1603780551582; Mon, 26 Oct 2020 23:35:51 -0700 (PDT) Received: from [192.168.1.254] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id h141sm209354qke.41.2020.10.26.23.35.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2020 23:35:50 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_50F0E227-4D8C-4512-9D73-1BC712C362A6" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Tue, 27 Oct 2020 02:35:49 -0400 In-Reply-To: Cc: Larry Garfield , =?utf-8?Q?Micha=C5=82_Marcin_Brzuchalski?= To: php internals References: X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Short-function syntax From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_50F0E227-4D8C-4512-9D73-1BC712C362A6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 26, 2020, at 10:23 AM, Micha=C5=82 Marcin Brzuchalski = wrote: >=20 > Hi Larry, >=20 > I'm wondering why we hadn't thought yet about reducing the need for = $this > in this syntax. > Since arrow functions have an ability to capture variables defined in > parent scope why not > think of the same for class properties which will automatically reduce > short methods verbosity. >=20 > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int =3D> $foo; > public function getBar(): int =3D> $bar; > } >=20 > And then going further why not removing =3D from arrow which indicated = that > there is no return value for void functions: >=20 > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int =3D> $foo; > public function setFoo(int $value): void > $foo =3D $value; > public function getBar(): int =3D> $bar; > public function setBar(int $value): void > $bar =3D $value; > } >=20 > The use of > instead of =3D> could if possible indicate the method = being void > and reduce even more: >=20 > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int =3D> $foo; > public function setFoo(int $value) > $foo =3D $value; > public function getBar(): int =3D> $bar; > public function setBar(int $value) > $bar =3D $value; > } >=20 > Would it be possible? >=20 > If not I think we should reanimate property accessors. Which brings us back to https://externals.io/message/64469 = from 7 years ago. And there is = this: = https://www.reddit.com/r/PHP/comments/budr7q/php_74_setters_and_getters_ha= ve_died/ = With getters/setters, it would seem Larry's proposal might allow for = more conciseness than it can with all other current syntax being the = same as PHP 8.0 per Nikita.=20 Consider this, as one straw man type of new syntax: class TimePeriod { private int $Seconds =3D 3600; public float $Hours { get():float =3D> $this->Seconds / 3600; set(int $v) =3D> $this->Seconds =3D intval($v*3600); } } Or for a different use-case with different straw man syntax that could = possibly work in addition to above syntax, where externally $Balance is = readonly whereas internally Balance is treated like it is private so it = can be set (I also used Michal's ">" to indicate void, although I am not = sure that using a greater-than in a different context is a good idea): class Account { public get int $Balance; public function Deposit(int $amount) > $this->Balance +=3D = $amount; public function Withdraw(int $amount) > $this->Balance -=3D = $amount; } -Mike >=20 > Just dropping my 50 cents. >=20 > Best regards, > Micha=C5=82 Marcin Brzuchalski --Apple-Mail=_50F0E227-4D8C-4512-9D73-1BC712C362A6--