Anonymous Self-Executing Functions in JavaScript and PHP
This post is more than 18 months old. Since technology changes too rapidly, this content may be out of date (but
that's not always the case). Please remember to verify any technical or programming information with the current
release.
I’ve used the anonymous self-executing paradigm a few times in JavaScript over the years. Something like this:
(function() {
console.log('So running. Much anonymous.');
})();
Then I started thinking - can I do the same thing in PHP (not a question of should, a question of can!) Turns out, you can still do it - just a different method of self-execution is required:
<?php
call_user_func(function() {
print "Oy - even PHP!";
});
That’s it for today!