[RFC] Short Functions

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #1139

    [RFC] Short Functions


    I do not like that with this RFC we end up with the following:

    function name($x) { return $x }
    function name($x) => $x;

    but for lambdas:

    $name = function ($x) { return $x }
    $name = fn ($x) => $x;

    this would be another wtf moment for future novice php learners.


    I see it’s all nice and quick to *write*. But what about reading?

    Apparently, it’s impossible ho have all methods written the same way. So it will be a mix between the two. but changing style always makes it hard to read. I foresee a PSR that would make the uniform syntax obligatory.

    I have a strange feeling: On the one hand, PHP is actively getting rid of alternative syntax such as ASP tags and creating PSRs to make the syntax uniform. On the other hand, at the same new alternative syntax is added. Is it only to have something to deprecate in the future?


    I think once you include the usual scope and type information for the function even a short one will be quite long for one line.


    Looks useless and an attempt to copy JS.


    >That provides extra visual clutter (especially when there are several such methods in one class).

    The reasoning seems to be written from the perspective of someone who doesn’t have mandatory PhpDoc comment blocks before every function. For us, using short functions like this would save us two lines per function on about 5% of our functions, taking those functions from around 6-10 lines each (including the docblock) to 4-8 lines each, which hardly helps.

    Besides, we all use PhpStorm, and it (like any proper IDE) lets you collapse functions you’re not looking at, which hides “visual clutter.”

    I’m not saying PHP shouldn’t add this, but I know we’d have almost no use for it, and I’d rather see PHP development efforts put toward fixing its core problems, like the library and the awful array type, rather than yet another pile of syntactic sugar.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.