PHP is a good programming language, if it is judged enough empirical parameters with the degree of diffusion and the amount of function that integrates. Often proves to be surprisingly flexible programming scenarios for addressing much more complex than simple embed script in a web page.

During a recent exchange of views with a mathematician fond of Open Source has presented the problem of creating anonymous functions, and - here's the rub - to do so within a PHP class. Skipping the theoretical claptrap I had to put up on the lambda calculus and anonymous functions, and I will only present here a passage of the definition given by WikiPedia . I quote:

The lambda calculus is a rewrite system defined formally by the mathematician Alonzo Church . It was developed to analyze formally the definitions of functions , their applications and is also an interesting tool for studying phenomena of recursion . As the rewriting system, it gives a description of well-formed terms, which are sequences of symbols recognized by the system and can be rewritten from it. The lambda calculus, in fact, defines a set of rewriting rules that determine precisely how the terms themselves can be rewritten. In this way, the process of rewriting becomes a real calculation .

And yet (available in English only):

Anonymous functions can be used to Contain functionality That need not be named for short-term and Possibly use. Some notable examples include closures and currying. [...]
Closures are functions Evaluated in an environment containing bound variables. The following example binds the variable "threshold" in an anonymous function That Compares the input to the threshold. [...]
Currying is a transforming function from multiple inputs to fewer inputs (in this case integer division).

Although not officially exist in PHP a real way to handle anonymous functions, you can easily get something similar in at least two ways:

  1. calling a variable with the name of a function:
    $foo = "phpinfo";
    $foo();
  2. initializing a variable with the `` create_function:
    $sum = create_function('$a, $b','return $a + $b;');
    echo $sum(1,2);

In the first case we are only creating a link to the function. In the second, instead, we assign the function to the variable just as we create it. Try it: it is an unusual appearance and somewhat fun of PHP, but strongly discourage anyone to adopt a similar solution in production environments where you do not want to lose sight of practicality and ease of reading the code.