-
-
Notifications
You must be signed in to change notification settings - Fork 522
Description
(Follow-up from #1485).
Currently (because of PHP 5.2) lambda/anonymous functions cannot be used in core. However once we move on to requiring a more recent PHP version, this will become possible.
Generally using lambda functions should be (strongly) discouraged as they usually miss documentation and context. There are some exceptions: for example very short callbacks in calls to array_filter(), array_udiff(), usort(), etc. may be better to be "inline lambda" rather than defined separately.
However in case of add_filter() and add_action() using lambda functions is "harmful". The anonymous callbacks cannot be removed and "break" remove_filter() and remove_action().
In that terms thinking we need a sniff to warn when a lambda callback is used in general (in case the code can be written better), and perhaps another sniff (or another configuration of the same sniff) specifically targeting add_filter() and add_action() and throwing an error when a lambda callback is detected there.