Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  75] [ 6]  / answers: 1 / hits: 20981  / 14 Years ago, wed, august 25, 2010, 12:00:00

In JavaScript, you can define anonymous functions that are executed immediately:



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


Can you do something like that in PHP?


More From » php

 Answers
202

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'; })();

[#95810] Monday, August 23, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quentinaveryb

Total Points: 102
Total Questions: 100
Total Answers: 93

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
quentinaveryb questions
Thu, Aug 6, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;