我有这个类(它是简单的卡片类):
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
我真的不明白出了什么问题。谁能帮我 ?