Use anonymous functions for single-use functions


I’m poking around a Sage fork I made, and I’m currently looking at the lib/utils.php file. In this file there’s a function being defined in the Roots\Sage\Utils namespace called get_search_form, which is used to point the get_search_form WP function to the template. Cool.

My question is why not make better use of anonymous functions throughout Sage in moments like these? The function will never be called directly, but it’s being defined and assigned a namespace. This adds unnecessary overhead. The only reason I’ve found to define single-use functions for hooks is if I’m anticipating that someone may later want to remove the hook instance – but I don’t think that applies here.

It’s a minor issue, but I figured I’d gauge thoughts on the idea. :smile:

1 Like

:+1: can you please submit a PR?

You got it!