我有這個類(這是簡單的卡類):PHP變量未定義錯誤
class Card{
private $suit;
private $rank;
public function __construct($suit, $rank){
$this->$suit = $suit;
$this->$rank = $rank;
}
public function get_suit(){
return $this->$suit;
}
public function get_rank(){
return $this->$rank;
}
}
我實例的每個卡(帶花色和等級)爲甲板:
$tmp_deck = array();
foreach ($SUITS as $suit){
foreach($RANKS as $rank){
array_push($tmp_deck, new Card($suit, $rank));
}
}
echo $tmp_deck[0]->get_suit();
和錯誤它給我:
Notice: Undefined variable: suit in card.php on line 13
我真的不能得到什麼是錯的。誰能幫我 ?
$ this-> suit = $ suit; $ this-> rank = $ rank; – 2013-02-22 11:38:53