M
M
mester2011-08-08 14:39:08
PHP
mester, 2011-08-08 14:39:08

Does PHP have an analogue of the Javascript construct (function() {})(); ?

Does PHP have an analogue of the Javascript construct (function() {})();?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Ivan, 2011-08-08
@mester

echo call_user_func( function() { return "hello"; } );

B
bioroot, 2011-08-08
@bioroot

What is it and why? You can create a function with create_function And more Note: Anonymous functions are available since PHP 5.3.0

A
Anatoly, 2011-08-08
@taliban

No, in the next version, it seems like such constructions should work, so far there is no analogue.

O
OlegTar, 2011-08-08
@OlegTar

There are closures in php.
if you can't create an anonymous function() function in php, then like this:
function closure() {
var $x = 1;
return function () //Returns an unnamed function
{
return $x * 2;
}
}
details here.
habrahabr.ru/company/mailru/blog/103983/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question