+ -
当前位置:首页 → 问答吧 → 类成员变量调用

类成员变量调用

时间:2011-07-20

来源:互联网

问题:类的成员变量无法被多个类的方法调用

class IndexAction extends Action{
public $testVal;
public function A(){
   $this->testVal='100';
   echo $this->testVal;
}

public function B(){
      echo $this->testVal;
}

}

问题是通过调用A方法可以给$testVal赋值并打印输出为100,调用B方法没有值?望朋友们帮忙解决下

作者: zhoujiale1985   发布时间: 2011-07-20

如果是程序中调用的话,需要先A,再B。

如果是在浏览器中访问的话,输出的应该是初始值。

作者: vus520   发布时间: 2011-07-20