PHP构造函数参数工作不正常


PHP constructor parameter not working properly?

不知怎么的,我的构造函数似乎不能正常工作:

private $matchId;
private $region;
private $date;
private $wAdc;
private $wSupp;
private $lAdc;
private $lSupp;
private $summoners;
public function _construct($matchId, $region, $date) {
    $this->matchId = $matchId;
    $this->region = $region;
    $this->date = $date;
    $this->summoners = array();
    $this->wAdc = null;
    $this->wSupp = null;
    $this->lAdc = null;
    $this->lSupp = null;
}
public function getMatchId() {
    return $this->matchId;
}

这里是对象创建:

$matchObj = new match($matchId, $region, $created);
$matches[] = $matchObj;
echo "a: ". $matchId . " ";
echo "b: ". $matchObj->getMatchId() . " ";

这里是我在浏览器中运行脚本时得到的输出:

a: 1936074952 b: 

因此,对象变量似乎没有正确设置。有人能帮我吗?

您忘记了一个下划线

它应该是public function __construct()

您的构造函数中有错误,请尝试以下操作:

public function __construct($matchId, $region, $date) {...}