"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > ## How to Execute Anonymous Functions Instantly in PHP?

## How to Execute Anonymous Functions Instantly in PHP?

Published on 2024-11-08
Browse:845

## How to Execute Anonymous Functions Instantly in PHP?

Executing Anonymous Functions Instantly in PHP

In JavaScript, defining and executing anonymous functions immediately is straightforward using the syntax:

(function () { /* do something */ })()

Is there a similar mechanism in PHP?

PHP 7

With PHP versions 7 and later, anonymous functions can be executed instantly and conveniently:

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

Pre-PHP 7

Prior to PHP 7, the only way to achieve immediate execution was through the call_user_func() function:

call_user_func(function() { echo 'executed'; });
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3