【发布时间】:2016-07-28 11:20:46
【问题描述】:
我的代码收到以下错误。请帮帮我。
警告:缺少 Personnage::__construct() 的参数 1,调用 public_html/PooEnPhp/index.php 在第 24 行并定义在 public_html/PooEnPhp/Personnage.class.php 在第 22 行
类文件:Personnage.class.php
<?php
class Personnage {
private $_force = 20;
private $_localisation = 'Lyon';
private $_experience = 0;
private $_degats = 0;
// Create a connstructor with two arguments
public function __construct($force, $degats) {
echo 'Voici le constructeur ! ';
$this->_force = $force;
$this->_degats = $degats;
}
Personnage 类的实例化文件:index.php
<?php
function chargerClasse($classe) {
require $classe . '.class.php';
}
//autoload the function chargerClasse
spl_autoload_register('chargerClasse');
// instantiate the Personnage class using the default constructor (the one implied without argument)
$perso = new Personnage();
通常在 index.php 中,我应该能够使用隐含的默认构造函数 __construct() 来实例化 Personnage 类。
但是我收到了上面的错误。谁能解释一下为什么?
谢谢
【问题讨论】:
标签: php constructor