How do I immediately execute an anonymous function in PHP?

For versions prior to PHP 7, the only way to execute them immediately I can think of is

call_user_func(function() { echo 'executed'; });

With current versions of PHP, you can just do

(function() { echo 'executed'; })();

Leave a Comment