似乎在调用函数时重新启动函数中声明的静态变量,如何以重新调用函数的方式使用该函数将重用静态参数?
我在static.php中定义了函数'testStatic'
这是static.php:
<?php
function testStatic()
{
static $staticV = 0;
echo $staticV;
$staticV;
}
?>
Run Code Online (Sandbox Code Playgroud)
我从index.php调用'testStatic'
这是index.php:
<?php include "./static.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3c.org/TR/html4/strict.dtd">
<?php
testStatic();
?>
<html>
.
.
.
<html>
Run Code Online (Sandbox Code Playgroud)
当index.php第一次执行时,testStatic将以'0'回显,但是在下一次执行index.php时,testStatic继续以'0'回显.似乎每当执行index.php时,都会重新启动'testStatic'的静态变量'staticV'.
请指教.index.php