" .print_r($var1,true).print_r($var2,true). ""; }}class Test{ /** * 静态变量、实例变量 **/ public static $staticVal = 1; public $instanceVal = 1; public function __construct() { $this->a(); $this->c(); p(self::$staticVal,"class static "); p($this->instanceVal,"class instance "); } public function a() { self::$staticVal++; $this->instanceVal++; } public function b() { static $val = 1; $val1 = 1; $val++; $val1++; p($val,"function static "); p($val1,"function instance "); } public function c() { self::$staticVal++; $this->instanceVal++; } //输出 public function dis() { p(self::$staticVal,"class static "); p($this->instanceVal,"class instance "); }}p("调用a,c方法,分别让类内两参数自增并输出");$test = new Test();p("再次调用a,c方法,分别让类内两参数自增并输出");$test->a();$test->c();$test->dis();p("调用b方法,分别让方法内两参数自增并输出");$test->b();p("再次调用b方法,分别让方法内两参数自增并输出");$test->b();
结果,类内静态、实例变量结果完全一样,但是方法内的静态参数会保留上一次计算的值,而实例变量每一次都会初始化。