<?php
class test extends Action{
private $x = '123';
function index(){
exit($this->$x);
}
}
?>这样访问比如说http://localhost/app/test
是打印不出来123的 因为this是指向当前对象实例的指针,不指向任何其他对象或类
test类没有new 所以$x没有得到值 不知道理解的对不?
试了下如果是static $x = '123'; exit(self::$x); 这样倒是可以
我想要定义类的属性并使用它们 难道必须定义成static然后用self吗?