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

时间:2015-02-04 13:08:35

标签: php

我的构造函数似乎无法正常工作:

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: 

所以对象变量似乎没有正确设置。有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:4)

你忘记了下划线

应为public function __construct()

答案 1 :(得分:1)

构造函数中存在错误,请尝试以下操作:

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