Tutorial on using static_PHP in php functions

WBOY
Release: 2016-07-13 17:51:45
Original
823 people have browsed it

function sendHeader($num, $rtarr = null) {
​ static $sapi = null;
If ($sapi === null) {
          $sapi = php_sapi_name();
}
Return $sapi++;
When looking at the PW source code, I found that the static keyword is used in the setHeader() function, which is very strange. It has never been used in this way before.
Static is used in functions. After a variable is declared once, if the function is called again, the initial value will be continued. For example, $sapi will be accumulated.

echo sendHeader(1)."
";
echo sendHeader(2)."
";
echo sendHeader(3)."
";
Output:

apache2handler
apache2handles
apache2handlet
It is similar to global, but the difference is the scope. static can only be used on this function.
Interesting. Needs further research.

Excerpted from zaric

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478180.htmlTechArticlefunction sendHeader($num, $rtarr = null) { static $sapi = null; if ($sapi == = null) { $sapi = php_sapi_name(); } return $sapi++; When looking at the PW source code, I found that the setHeader() function uses...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template