duanjue9296
duanjue9296
2015-02-04 13:08
浏览 35
已采纳

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

Somehow my constructor doesn`t seem to work 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;
}

And here the object creation:

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

And here the output I get when I run the script in my browser:

a: 1936074952 b: 

So the object variable doesn`t seem to get set properly. Could anybody help me out?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtt78245
    dtt78245 2015-02-04 13:10
    已采纳

    You forgot a underscore

    It should be public function __construct()

    点赞 评论
  • douchen5971
    douchen5971 2015-02-04 13:11

    There is an error in your constructor, try this:

    public function __construct($matchId, $region, $date) {...}
    
    点赞 评论

相关推荐