On 2025-04-02 00:14, Ilija Tovilo wrote:
On Tue, Apr 1, 2025 at 12:40 PM Tim Düsterhus <t...@bastelstu.be> wrote:

If you are at the point where you need mutually recursive closures,
perhaps you should just use named functions / an anonymous class. I
don't find it useful to “optimize DX” for that case, since
self-recursive Closures are already somewhat questionable / rarely used
(though I think I've used that myself a handful of times in the past).

I don't disagree. To reveal my ulterior motive: References [1].


I don't disagree either - though maybe I tend to write more functionally than is maybe idiomatic for PHP, so I'm already more comfortable with both passing closures around and recursion. At the moment though, use-by-reference is the mechanism with the smallest developer footprint. Just pay attention to what you're storing in your local variables (you don't have so many you're losing track, right?) and you won't get bitten.

As for other uses ... I can't find the last time I used & in foreach() to modify an array's elements in-place (though I'm sure there are some somewhere), I don't think I've ever created a function with a by-reference parameter, and I can find precisely one instance where I used it to abbreviate a long-winded multidimensional array lookup that I would have otherwise had to write several times (including an assignment).

Reply via email to