Use static in php functions. Copy the code as follows: functionsendHeader ($ num, $ rtarrnull) {static $ sapinull; if ($ sapinull) {$ sapiphp_sapi_name ();} return $ sapi ++; when reading PW source code, we found
The code is as follows:
Function sendHeader ($ num, $ rtarr = null ){
Static $ sapi = null;
If ($ sapi === null ){
$ Sapi = php_sapi_name ();
}
Return $ sapi ++;
When reading the PW source code, I found that the setHeader () function uses the static keyword. it is strange that it has never been used before.
Static is used in the function. after a variable is declared, if this function is called again, it will continue at the initial value. for example, $ sapi will accumulate here.
The code is as follows:
Echo sendHeader (1 )."
";
Echo sendHeader (2 )."
";
Echo sendHeader (3 )."
";
Output:
The code is as follows:
Apache2handler
Apache2handles
Apache2handlet
It is a bit similar to global, but the difference is the scope. Static can only act on this function.
A little interesting. In-depth research is required.
The http://www.bkjia.com/PHPjc/325414.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325414.htmlTechArticle code is as follows: function sendHeader ($ num, $ rtarr = null) {static $ sapi = null; if ($ sapi = null) {$ sapi = php_sapi_name ();} return $ sapi ++; found when reading PW source code...