我已經被$this
。我困惑知道用於闖民宅全球價值$this->somevaribale
單獨行動......但我已經見過像
class ClassName
{
private $array; //set up a variable to store our array
/*
* You can set your own array or use the default one
* it will set the $this->array variable to whatever array is given in the construct
* How the array works like a database; array('column_name' => 'column_data')
*/
function __construct($array = array('fruit' => 'apple', 'vegetable' => 'cucumber')) {
$this->array = $array;
}
/*
* Loops through the array and sets new variables within the class
* it returns $this so that you may chain the method.
*/
public function execute() {
foreach($this->array AS $key => $value) {
$this->$key = $value; //we create a variable within the class
}
return $this; //we return $this so that we can chain our method....
}
}
這裏$this
代碼單獨叫.. .Am真的與此混淆。當我刪除$ this並用$ this->數組替換時出現錯誤。
所以我的問題是單獨調用$this
以及它代表什麼。
Thanx的幫助。
$這是指包含'$ array'的對象。 – Wold 2014-09-23 16:55:56
查看流利的界面 – 2014-09-23 16:56:42
@Wold包含$ array的對象意味着?? .. supose如果我打電話就像$ wold = new classname()..so $ this指的是$ wold ?? – 2014-09-23 16:58:23