Uncallable Function

no-email (Damien Seguy), Damien Seguy
Wed, 20 Dec 2023 00:00:00 +0000

The function foo() cannot be called. When the code does so, nothing happens.
The trick is the inclusion of a call to yield (or yield from) in the function. It turns the function into a generator, and calling it directly does nothing. It needs to be called with foreach() or iterator_to_array().
This trick applies to functions, arrow functions, closures and methods.