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

WBOY
Release: 2016-07-21 15:02:02
Original
873 people have browsed it

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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!