为什么获取不到类里面的属性值呢?

浏览:882 发布日期:2013/02/18 分类:求助交流
<?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吗?
最佳答案
评论( 相关
后面还有条评论,点击查看>>