- Function & func (){
- Return "";
- }
2. add a reference symbol before the function during the call.
- $ Return = & func ();
PHP has only two types of scopes: external functions and global scopes. 2. local scope within the function. Rule: The scope does not overlap. (Local access is not allowed globally, and local access is not allowed globally) but js can overlap. Special: pre-defined variables (9 super-global array variables) -- note that they are array variables. Ultra Global: Super Global: it can be used globally or locally. All scopes take effect.
- $ _ GET ['v1 '] = "123 ";
- Echo $ _ GET ['v1 ']
-
$ GLOBALS is a super global variable that stores Super global variables. Note that there is no underline. Modifying global variables affects the values of elements in GLOBALS; Cause: A data space used. Equivalent:
- $ GLOBALS ['V8 '] = & $ v8;
2. create_function -- create a function in another way
- $ Func = create_function ('$ P', "echo $ p );
Var_dump ($ func); returns a function name. The name of the function created by the sub-function is lambda. In addition, there is an invisible character before the function name. Invisible characters with Ascii 0. It can also be called. $ Result = "\ x0". "lamba8" (20). you must know the function name before calling it. The most common part appears in the callback function. Therefore, the functions created by create_function are no different from normal functions (there are three parts of the function ); However, this function cannot be called before it is specified. Therefore, you only need to execute create_function to obtain this function. Most commonly used: On the callback parameter, the create_function parameter is equivalent to a callback structure input parameter. Anonymous function: a function created by an anonymous function has no name, but an object: the difference with create_function: What is an anonymous function? 1. you can view anonymous functions on duty (object type in php). 2. Php implements anonymous functions through the closure class. Every anonymous function is an object of the Closure class. Closure indicates a Closure. So sometimes php calls an anonymous function a closure function. 3. Why can an object be called as a function? (Oop) You can use the syntax of variables in the outer scope: Note: the difference between the outer layer and the Global layer. The outer layer may be global or local. The current anonymous function is defined. The Use syntax defaults to value transfer, which can be referenced and passed. Callback1, Function name 2, Create_function3, Function anonymous Function |