PHP 7.4
Anonymous functions in PHP can be quite verbose, even when they only perform a simple operation. Partly this is due to a large amount of syntactic boilerplate, and party due to the need to manually import used variables. This makes code using simple closures hard to read and understand.


  • 1
    I think this rfc makes simple closures hard to read and understand (or that’s what you meant?). Easier to write - yes, read - nope, and makes it look like javascript.
  • 3
    @SevenDeadlyBugs I think so too , I think php make it easier for javascript developers not for everyone :D
  • 0
    I like them :D

    Im just waiting for the alpine repositories to finally compile 7.4
  • 3
    @SevenDeadlyBugs "You... you take that back or else! I don't mind a little criticising, but there are limits! To say that it looks like JS, pfff..."
  • 2
    They made this to follow the Frontend developers, unfortunately, I try to help with PHP evolving and try to contribute for the language, but I totally disagree with this RFC, this is just coming to make the new-gen of developers easier to write the code (e.g. JavaScript developers) but make it less readable.

    The code above on the screenshot shows it by itself.

    Once I opened a post in a forum of PHP developers to suggest to create a new filter for those who vote in new features and get people who has more backend and real PHP / C / C++ background and my post was deleted and I got a ban because I was "disrespecting" the others developers and this is not the goal of the open-source.

    Anyway, unfortunately now in open source we have more involve political people than real technical people who care about language and its purpose.
  • 1
    PHP was always community driven, and took everyones opinion into account, that’s what made it popular, but that’s what also fucked it up, it’s basically “if community wants it, then we’re going to do it”, and further it goes, less professional input it gets.

    I guess we should move to other languages, which are too hard to grasp for javascript “developers”. Rust, golang and similar are doing great job at keeping those feature freaks out.
  • 1
    I'm not really seeing the issue here. How is that less readable? Arrow syntax for lambdas is practically an established thing, regardless of Javascript. I'd much rather have that, than having to mentally sift through all the keywords and other symbols to get to the meaning.

    Java uses this syntax too, which is one of the widely used backend technologies.

    Rust, mentioned in the thread, would have: |x| arr[x], which is not that far off from the example given above.

    And someone mentioned C++, here's the C++ example: [&arr](int x) { return arr[x]; }. How is that more desireable?

    Why is there so much disrespect for other developers, especially Javascript?

    Disclaimer: I'm not a Javascript developer.
  • 1
    @SevenDeadlyBugs I would like to try, in fact, I have some knowledge in Python and Golang, but usually, to work with nowadays again they ask a lot of years of experience, something is not easy to get and a lot of companies don't give a care for freelancer projects.

    I have 8 years of PHP and watched and participated in its evolution and I cannot imagine trowing this away like that, we need to participate more in the community and show to them how those things in fact it's not a real improvement of the language comparing what we asked to improve.
  • 2
    @frankot Yes, your example is readable, and you give a small function portion.

    Imagine a file of 400 lines with fn($var) => whatever

    And this is was something I found here every day, function without names and arrow functions appearing and being abused.

    Java goes to this path because the community of android developers asked this and makes all the sense since they have to handle a lot of UI issues and etc, so the language should be written more easily instead more "readable" (let's call in that way).

    But what's the use of this for PHP? We have a lot of RFC to be voted what could be EVEN more useful for us and for the community.
  • 1
    Another example of the useless of this also is the RFC of Data Structures, It has been for years we ask to PHP start give attention to DS and make the PHP not only a high-level language to write code but also start became a real server-side language with proper binaries for structures.

    And guess what? No one care, the version 7.0 to 7.4 this arrow functions became more discussed than start give strict types for variables what should be implemented on 7, but the new-gen community was more concerned to make more easy code to make the language stronger.

    I believe the language should be easy to write for the programmer, but also the language should give consistency to the code, and an example which don't let me lie about that it's Python.
  • 0
    @messhias Can you please show me an example where short closure is less readable than full closure? Keep in mind that short closures in php are limited to one statement and do not allow multiple lines. For those you need full closures.

    As for making it more like javascript... not really. Its not something "invented" in Javascript. It's just popular there. If you remember, JS didn't even have arrow functions until around 5 years ago. I've been waiting for short closures since the rfc got passed. It makes so many things easier to read.

    And the use? All of php native functions with closures can now be concise one liners, frameworks which use closures now can be more concise for most mapping uses. No need to define use() anymore. More concise and readable implementations of mapping, nicer way to set behaviors and events in architecture software design, etc...

    I think you should give them a try without just dismissing them outright.
Add Comment