PHP Method for referencing local static variables of operations and external operation functions, static variables
Static variables in external operation functions or member methods by reference
The following is a simple example to illustrate three references:
1. type conversion in the function after parameter reference is also an address operation
2. If the parameter is referenced and passed to another function, you must add a reference character to maintain the address operation.
3. The reference operator must be added when the function is declared and called.
This example uses Object method operations and is also applicable to functions.
<? Phpclass A {public function & test1 (& $ a) {static $ I = 0; var_dump ($ I); $ a = (array) $; $ a ['domain '] = 'HTTP: // blog.csdn.net/zhouzme'{$this-> test2 ($ a); $ I ++; var_dump ($ a); var_dump ($ I ); return $ I;} protected function test2 (& $ a) {$ a ['name'] = 'snail ';}}$ obj = new (); $ a = ''; $ c = & $ obj-> test1 ($ a); $ c ++; var_dump ($ ); $ obj-> test1 ($ a); var_dump ($ );
Output result
References to local static variables first
Look at this question: e is declared outside the function body. It is not a local variable and it is global, in this source file, all functions following the static int e statement can be used, and the extern keyword is not required.
If you correctly asked whether a static local variable is available in other functions? The answer is no.
Local variables are only available in this function, whether static or not
PHP has no Global static variables, such as class {public static int INY = 0;} Like java, which can be called on any jsp page
There are global variables, but if you want to call files that require include or require containing global variables on different pages.
Global keywords are required to call global variables in a function or class.
Example:
1. php
<? Php
$ A = "test ";
?>
2. php
<? Php
Include ("1.php ");
// Or require ("1.php ");
Echo $;
// Output test
?>
Function call
<? Php
$ A = "test ";
// You can also use require/include from other files
/* It can also be a class */
Function (){
Global $ a; // introduce global variables
Return $;
// You can also remove global and directly return $ GLOBAL ['a'];
}
Echo a (); // output test
?>
If you need a real global variable, you can use session or cookie to store it.
References: Years of programming experience