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.

Just dropping my 50 cents.

Best regards,
Michał Marcin Brzuchalski

wt., 20 paź 2020 o 20:20 Larry Garfield <la...@garfieldtech.com> napisał(a):

> A while back, Nikita mentioned that it should now be easy to offer an
> abbreviated syntax for functions that are just a single expression.  I
> decided to take a crack at it and it turns out he was right.  I thus offer
> this RFC:
>
> https://wiki.php.net/rfc/short-functions
>
> Hopefully I made a decent enough case for it.  It's entirely a convenience
> factor, but I think for many OOP cases (getter methods and factored out
> operations) and functional cases (where functions should generally be a
> single expression conceptually) it does make the code nicer, more compact,
> and more readable.
>
> *dons flame retardant suit*
>
> --
>   Larry Garfield
>   la...@garfieldtech.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

Reply via email to