On Wed, Nov 4, 2020, at 4:05 PM, Nuno Maduro wrote:
> Hey Larry,
> 
> In my vision, this proposal is a good addition to PHP exactly as stated in
> this pull request (https://github.com/php/php-src/pull/6221): where only
> the "=> expr;" is introduced, and not the "fn".
> 
> For visual consistency in the future of PHP functions/methods, I think it's
> important to differ "=> expr;" from "fn":
> 
> - "=> expr;" means "arrow": syntax that defines functions/methods with
> one-line return expressions.
> - "fn" means "short": syntax that makes functions inherit scope. It's
> already in use by arrow short closures (
> https://wiki.php.net/rfc/arrow_functions_v2 ).
> 
> Therefore, from my understanding, your proposal would allow all the
> following things to be possible:
> ```php
> // arrow function
> function foo() => /** */;
> 
> // arrow closure
> $foo = function () => /** */;
> 
> // fn/short arrow closure ( already introduced in PHP 7.4 )
> $foo = fn() => /** */;
> 
> class Foo {
>     // arrow method
>     poublic function bar() => /** */;
> }
> ```
> 
> If this proposal keeps using the "function", and not the "fn", I don't see
> any conflict with my Proposal (multi-line short closures -
> https://github.com/php/php-src/pull/6246).
> 
> Good luck with the RFC.
> 
> - Nuno

Yes, that's how it would fall out, assuming multi-line-arrows happen.  I'm 
honestly still torn on that myself for various reasons, but "=> means 
expression, fn means auto-capture, use one or both as appropriate" seems like a 
reasonable syntax guideline that we can teach people.

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to