Skip to content

Shorter functions #6379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed

Shorter functions #6379

wants to merge 7 commits into from

Conversation

Crell
Copy link
Contributor

@Crell Crell commented Oct 23, 2020

An alternate version of #6221 that uses fn instead of function. Same RFC.

@nunomaduro
Copy link
Contributor

nunomaduro commented Oct 24, 2020

Hey @Crell, @sgolemon,

I would prefer this to stick with the version proposed #6221.

In my opinion, to have some visual consistency in the future of PHP shorter functions/methods, this would be the way to go:

Here are some examples I find interesting following what I've just proposed:

// Global or namespaced functions scopeless
function foo() {} // function
function foo() => /** */; // arrow function

// Global or namespaced functions with access to the parent scope
fn foo() {} // short function
fn foo() => /** */; // short arrow function

// Closures scopeless
$foo = function () {}; // closure
$foo = function () => /** */; // arrow closure

// Closures with access to the parent scope AKA https://github.com/php/php-src/pull/6246
$foo = fn() {}; // short closure
$foo = fn() => /** */; // short arrow closure

class Foo {
    // Methods scopeless
    function foo() {} // method
    function foo() => /** */; // arrow method

    // Methods with access to the parent scope
    fn foo() {} // short method
    fn foo() => /** */; // short arrow method
}

@Crell
Copy link
Contributor Author

Crell commented Oct 26, 2020

I don't even know what parent scope means for a method... 😄

Let's discuss this on the mailing list, not in disperate PRs.

@cmb69 cmb69 added the RFC label Oct 27, 2020
@redbastie
Copy link

redbastie commented Feb 4, 2021

I don't even know what parent scope means for a method... 😄

Let's discuss this on the mailing list, not in disperate PRs.

He means that the function is scoped within the parent class so it wouldn't pollute the global namespace, but then again that wouldn't make any sense as you could just create a class method lol

This however, is the sexiest thing ever:

class Foo {
    fn bar() => /** */; // short arrow method
}

@Crell Crell closed this Jun 15, 2021
@Crell Crell deleted the shorter-functions branch June 15, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants