[英]Difference between $this->a and $this->$b in PHP
有什么區別:
$this->$a
和$this->b
在我的班上,我有這個:
class someClass{
public $a;
function aFunction(){
$this->a = 5;
$this->$b = 7;
}
}
什么讓額外的'$'在$this->$b
有很多不同之處:
$this->a
指$a
是您班級的財產$a
$this->$b
另一方面$this->$b
是通過名稱引用的屬性,它作為字符串存儲在變量$b
中:
$b = "a";
$this->$b equals $this->a
$b = "hello"
$this->$b equals $this->hello
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.