logoalt Hacker News

pwdisswordfishytoday at 8:57 AM2 repliesview on HN

Why? The article fails to explain.

> The introduction of first-class callables simplifies callback handling. You no longer have an excuse to define your callbacks like this:

> <?php

> $data = array_map(trim(...), [' x', 'z ']);

“First-class callables” is that exact syntax.


Replies

joe_hoyletoday at 1:36 PM

The problem is that first class callables actually makes a new object wrapper for each reference, so trim(…) != trim(…). (It can be true in some cases, it depends if the memory is freed for the first reference).

show 1 reply
donatjtoday at 11:31 AM

Exactly. The article kind of circles around the idea that it's bad, but never really lands on why.

My experience is with modern annotations, callable and iterable are pretty powerful, convenient, and safe.

- https://phpstan.org/writing-php-code/phpdoc-types#callables

- https://phpstan.org/writing-php-code/phpdoc-types#iterables