> On Oct 26, 2020, at 10:23 AM, Michał Marcin Brzuchalski 
> <michal.brzuchal...@gmail.com> wrote:
> 
> Hi Larry,
> 
> 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.
> 
> class X {
>    public function __construct(private int $foo, private int $bar) {}
>    public function getFoo(): int => $foo;
>    public function getBar(): int => $bar;
> }
> 
> And then going further why not removing = from arrow which indicated that
> there is no return value for void functions:
> 
> class X {
>    public function __construct(private int $foo, private int $bar) {}
>    public function getFoo(): int => $foo;
>    public function setFoo(int $value): void > $foo = $value;
>    public function getBar(): int => $bar;
>    public function setBar(int $value): void > $bar = $value;
> }
> 
> The use of > instead of => could if possible indicate the method being void
> and reduce even more:
> 
> class X {
>    public function __construct(private int $foo, private int $bar) {}
>    public function getFoo(): int => $foo;
>    public function setFoo(int $value) > $foo = $value;
>    public function getBar(): int => $bar;
>    public function setBar(int $value) > $bar = $value;
> }
> 
> Would it be possible?
> 
> If not I think we should reanimate property accessors.

Which brings us back to https://externals.io/message/64469 
<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_have_died/
 
<https://www.reddit.com/r/PHP/comments/budr7q/php_74_setters_and_getters_have_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. 

Consider this, as one straw man type of new syntax:

class TimePeriod {
        private int $Seconds = 3600;
        public float $Hours {
                get():float => $this->Seconds / 3600;
                set(int $v) => $this->Seconds = 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 += $amount;
        public function Withdraw(int $amount) > $this->Balance -= $amount;
}


-Mike

> 
> Just dropping my 50 cents.
> 
> Best regards,
> Michał Marcin Brzuchalski

Reply via email to