这是一个对象内的一个函数内部的语句
foreach ( (array) $this->tables as $table )
$this->$table = $this->prefix . $table;
请问,->后面有没有$啥区别呢?

解决方案 »

  1.   

    $this->tables 是 this 里的变量
    $table 是一个独立的变量不隶属于 this.
    不知道对不对 哈哈哈.你写个类就知道了.
      

  2.   

    请看手册中:变量的变量$this->$table = $this->prefix . $table;
    若把 this-> 去掉
    $$table = $prefix . $table;这就没有疑问了吧?
      

  3.   

    区别就是:
    $this->tables 是正确的语法;
    $this->$table 是错误的语法。
    --------
    With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is
    hard to be sure where they are going to land, and it could be dangerous sitting under them as they
    fly overhead.
      

  4.   

    $this->tables //tables是$this的属性
    $this->$table //$table要是一个已知的变量,不能为空,你可以传递变量,就如同原来的__set似的
      

  5.   


    //举个例子
    class People{ function setPrototype($protorype, $value){
    $this->$protorype = $value;
    }
    }
    $p = new People();
    $p->setPrototype('username', 'zhangsan');
    $p->setPrototype('gender', 'man');
    $p->setPrototype('age', '20');
    echo '<pre>';print_r($p);
      

  6.   

    class a {
    public $a = 'i am a';
    public function test() {
    echo $this->a,"\n"; $b = 'a';
    // 加个这个应该明白了吧
    echo $this->{$b},"\n";
    }
    }$a = new a();$a->test();
      

  7.   

    根据hnxxwyq的例子再改得复杂一些。
       class a {
        public $a = 'abc';
    public $abc='woaini';
    public $b = 'b';
        public function test() {
           
            $b = $this->a;// 把变量b指向a表示的abc字符。即$b='abc';那么下面调用的时候就变成了$this->abc
     
    echo $this->a,"<br>"; //这个就是上面定义的 $a = 'abc';
            echo $this->b,"<br>";  //这个就是上面定义的 $b = 'b';
    echo $this->$b,"<br>"; //$this->$b实际就是访问$this->abc
        }
    }
    $a = new a();
    $a->test();
    所以,我认为:$this->$table和$this->table本质上并无区别。只是指针变量引用上一个为常量(不加$)。一个为变量(加$)!
      

  8.   

    sorry, 我错了!我只是随便写了几行程序,结果运行没通过,我就以为是语法错误。没想到当“$table 的值是一个字符串,而这个字符串恰好是 $this 中一个成员变量的名字“的时候,$this->$table 这种语法就特别有用了。非常抱歉!
      

  9.   

    $t="sdf"
    $this->sdf=30;
    echo $this->$t;//display 30
      

  10.   

    $this->tables 引用该类的tables属性$this->$tables 引用$tables变量的值对应的变量。比如
    $tables="name";
    $this->$tables==$this->name;
      

  11.   

    你就把$this->$tables理解成$$tables吧
    即将变量的值作为变量名