PHP 5.5.6(在方法之间交换数据)从getValue方法调用私有方法和静态变量,只有在设置新值后才能工作


PHP 5.5.6 (exchangeing data between methods) calling private method and static variable from getValue method, works only after setting new value

请有人向我解释一下这个错误的原因是什么?。。在为$variable 分配新值后,为什么它工作良好

<?php
 class MyClass {
   var $variable = 'first_variable';
   static $qt = 1;
   public function getValue() {
     return $this->variable . ' - calling getValue: ' . MyClass::increment();
   }
   public function setValue($pass) {
     return $this->variable = $pass;
   }
   private function increment() {
     return $this->qt++;
   }
 }
 $ob = new MyClass();
 echo $ob->getValue();
 $ob->setValue('changed_variable');
 echo '<br>' . $ob->getValue();
 echo '<br>' . $ob->getValue();
 echo '<br>' . $ob->getValue();

只对第一个值给出错误,然后运行良好,

错误:注意:第18行C:''examplep''htdocs''somename''1.php中未定义的属性:MyClass::$qt

first_variable - calling getValue:
changed_variable - calling getValue: 1
changed_variable - calling getValue: 2
changed_variable - calling getValue: 3

在这种情况下,问题是我试图将静态属性作为非静态属性访问。分辨率是

private function increment()
 { 
return MyClass::qt++; 
}