区别就是: $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.
//举个例子 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);
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();
根据hnxxwyq的例子再改得复杂一些。 class a { public $a = 'abc'; public $abc='woaini'; public $b = 'b'; public function test() {
$table 是一个独立的变量不隶属于 this.
不知道对不对 哈哈哈.你写个类就知道了.
若把 this-> 去掉
$$table = $prefix . $table;这就没有疑问了吧?
$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.
$this->$table //$table要是一个已知的变量,不能为空,你可以传递变量,就如同原来的__set似的
//举个例子
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);
public $a = 'i am a';
public function test() {
echo $this->a,"\n"; $b = 'a';
// 加个这个应该明白了吧
echo $this->{$b},"\n";
}
}$a = new a();$a->test();
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本质上并无区别。只是指针变量引用上一个为常量(不加$)。一个为变量(加$)!
$this->sdf=30;
echo $this->$t;//display 30
$tables="name";
$this->$tables==$this->name;
即将变量的值作为变量名