Home  >  Article  >  Backend Development  >  A brief analysis of the use of PHP variable modifier static_PHP tutorial

A brief analysis of the use of PHP variable modifier static_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:02873browse

Static variables only exist in the local function scope, but their values ​​are not lost when program execution leaves this scope. Take a look at the following example:

Copy the code The code is as follows:

function test(){
static $a= 0;
$a++;
echo $a;
}

test();//1
test();//2
test( );//3
Note: Static variables can be declared as shown in the above example. Assigning it with the result of an expression in a declaration will result in a parsing error.
Copy code The code is as follows:

static $a=0+1;
static $a=sqrt(121 );

The above assignment method will report an error. If you don’t believe me, try it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327941.htmlTechArticleStatic variables only exist in the local function scope, but when the program execution leaves this scope, its value does not lost. Take a look at the example below: Copy the code The code is as follows: function test(){ static...
Statement:
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