Summary of PHP functions
1. General functions
2. Variable functions
function myfun ($a) { echo$a;} $b = "Myfun"; $b ("Test");
3. Anonymous function (can implement closures)
An anonymous function (Anonymous functions), also called a closure function (Closures), allows temporary creation of a function without a specified name, often as a parameter to a callback function (callback), and of course other applications
$func function () {}; // to bring a semicolon $func // called Var_dump ($func); // returns the object Type objects (Closure) #1 (0) {}
4. Closure function: The anonymous function in the normal function as a parameter in and out, you can also be returned, the implementation of a simple closure.
In layman's terms, a child function can use a local variable in the parent function, which is called a closure.
Features of closures:
1. As a reference to a function variable, when the function returns, it is in the active state.
2. A closure is when a function returns, a stack that does not release resources
In fact, the above two points can be synthesized a little, that is, when the closure function returns, the function internal variables are active, the function of the stack area is still retained.
functionMyFunc () {$a=10; $b=11; $one=function($str) Use(&$a,$b){//Use reference outer variable does not add & copy does not affect parent function value Echo $a=$a+2; Echo' <br/> '; Echo $b=$b+2; Echo' <br/> '; Echo $str; }; Echo $a; Echo'---<br/> '; Echo $b; Echo'---<br/> '; return $one;}$a=MyFunc ();$a(' Hello ');
The parent function returns the anonymous function as the return value, one of the closures:
5. Intrinsic functions
Extended knowledge php:use Use of keywords
1. Namespaces
2. Closure function context
3.Trait code reuse Reference .... (Refer to http://php.net/manual/zh/language.oop5.traits.php)
Previous post: http://www.cnblogs.com/fps2tao/p/8727248.html
PHP function Summary (closure function, anonymous function)