php - Warning: Missing argument 1 for Personnage::__construct() -


i receiving following error code. please me out.

warning: missing argument 1 personnage::__construct(), called in public_html/pooenphp/index.php on line 24 , defined in public_html/pooenphp/personnage.class.php on line 22

class file : personnage.class.php

<?php  class personnage {      private $_force =  20;     private $_localisation = 'lyon';     private $_experience = 0;     private $_degats = 0;        // create connstructor 2 arguments     public function __construct($force, $degats) {         echo 'voici le constructeur ! ';          $this->_force = $force;         $this->_degats = $degats;     } 

the file instantiating personnage class: index.php

<?php              function chargerclasse($classe) {                 require $classe . '.class.php';              }              //autoload function chargerclasse             spl_autoload_register('chargerclasse');             // instantiate personnage class using default constructor (the 1 implied without argument)             $perso = new personnage();  

normally in index.php should able instanciate the personnage class using implied default constructor __construct().

but getting error above. can explain me why ?

thanks

the problem in here:

// create connstructor 2 arguments public function __construct($force, $degats) {     echo 'voici le constructeur ! ';      $this->_force = $force;     $this->_degats = $degats; } 

the $force , $degates both set obligatory parameters. able call new personnage() setting parameters have change class this:

<?php class personnage {      private $_force =  20;     private $_localisation = 'lyon';     private $_experience = 0;     private $_degats = 0;      // create connstructor 2 arguments     public function __construct($force = 20, $degats = 0) {         echo 'voici le constructeur ! ';          $this->_force = $force;         $this->_degats = $degats;     } }  

?>

this sets default values parameters ok not supply them.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -