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: 
Since PHP 5.3 you can create anonymous functions like this:

```
$var = 1;
$func = function( $arg ) use ($var) {
     return $arg + $var;
};

```

The `use` clause is required to access variables defined outside the anonymous function.

If you want to change an outside variable in the anonymous function you have to declare it as an reference (by adding an `&` in front of the `$`) in the `use` part:

```
$var = 1;
$func = function() use ( &$var ) {
   $var = 42;
}
$func();
// $var == 42 now

```

Otherwise changes made in the anonymous function will not be propagated to the outside.
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.