<?php
//静态局部变量
function static_function() {
static $i=0;
$i++;
}
static_function();//1
static_function();//2
static_function();//3
//静态成员变量
//Zend为每个函数分配了一个私有的符号表来保存该函数的静态变量。
class static_class {
public static $i=0;
public function get_static() {
return ++self::$i;
}
}
$class1 = new static_class();
$class2 = new static_class();
PD9waHAKCi8v6Z2Z5oCB5bGA6YOo5Y+Y6YePCmZ1bmN0aW9uIHN0YXRpY19mdW5jdGlvbigpIHsKCXN0YXRpYyAkaT0wOwoJJGkrKzsKCXByaW50X3IoJGkpOwp9CnN0YXRpY19mdW5jdGlvbigpOy8vMQpzdGF0aWNfZnVuY3Rpb24oKTsvLzIKc3RhdGljX2Z1bmN0aW9uKCk7Ly8zCgovL+mdmeaAgeaIkOWRmOWPmOmHjwovL1plbmTkuLrmr4/kuKrlh73mlbDliIbphY3kuobkuIDkuKrnp4HmnInnmoTnrKblj7fooajmnaXkv53lrZjor6Xlh73mlbDnmoTpnZnmgIHlj5jph4/jgIIKY2xhc3Mgc3RhdGljX2NsYXNzIHsKCXB1YmxpYyBzdGF0aWMgJGk9MDsKCXB1YmxpYyBmdW5jdGlvbiBnZXRfc3RhdGljKCkgewoJCXJldHVybiArK3NlbGY6OiRpOwoJfQp9CiRjbGFzczEgPSBuZXcgc3RhdGljX2NsYXNzKCk7CiRjbGFzczIgPSBuZXcgc3RhdGljX2NsYXNzKCk7CnByaW50X3IoJGNsYXNzMS0+Z2V0X3N0YXRpYygpKTsvLzEKcHJpbnRfcigkY2xhc3MyLT5nZXRfc3RhdGljKCkpOy8vMgo=