标签:extends 例子 his span comm 全局变量 protect 理解 function
关键字$this代表其所在的当前对象
使用当前对象的属性和方法 $this->取值
方法内的局部变量 不能用$this 关键字取值
要调用全局变量:必须用$this来调用
例子
class A extends AdminbaseController{
protected $id=0;
public function index(){
echo $this->id;//调用得到
echo $id;//调用失败
$this->display();
}
}
要调用局部变量,$id理解为局部变量
class A extends AdminbaseController{
protected $id=0;
public function index(){
$id=0;
echo $id;//调用失败
$this->display();
}
}
标签:extends 例子 his span comm 全局变量 protect 理解 function
原文地址:http://www.cnblogs.com/YangJM/p/7070895.html