Question: In JavaScript you can have:

```
var blabla = function(arg){
  ...
};

```

Is there something like this in PHP?

I know about `create_function()`, but it's really complicated to stuff your code in a string argument.

Answer: 
They are called anonymous functions. In [PHP >= 5.3](http://php.net/manual/en/functions.anonymous.php) you can do:

```
$func = function($a, $b) {
    return $a + $b;
};

$result = $func(3, 4); // returns 7

```

You can even have closures:

```
$c = 5;
$func = function($a, $b) use ($c) {
    return ($a + $b) * $c;
};

$result = $func(3, 4); // returns 35

```

But be aware: the following JavaScript snippet can only be reproduced in PHP using references:

```
var c = 5;
var f = function(a, b) {
    return (a + b) * c;
};
var r = f(3, 4); // returns 35
c = 6;
r = f(3, 4); // returns 42

```

In PHP this must look like:

```
$c = 5;
$func = function($a, $b) use (&$c) {
    return ($a + $b) * $c;
};

$result = $func(3, 4); // returns 35
$c = 6;   
$result = $func(3, 4); // returns 42

```

Prior to 5.3 you have to use `create_function()` to create anonymous functions.
Yes, it is available in php 5.3.X

<http://php.net/manual/en/functions.anonymous.php>

```
<?php
$greet = function($name)
{
    printf("Hello %s\r\n", $name);
};

$greet('World');
$greet('PHP');
?>

```