PHP[OOP] - How to call class constructor manually?

前端 未结 6 484
时光取名叫无心
时光取名叫无心 2020-12-30 07:47

Please see the code bellow:

01. class Test {
02.     public function __construct($param1, $param2, $param3) {
03.         echo $param1.$para         


        
6条回答
  •  春和景丽
    2020-12-30 07:58

    to construct your object first and then pass parameters your could try this way:

    class Test {
        public function __CONSTRUCT($p1="Bundy", $p2="house", $p3=10) {
            $this->init($p1, $p2, $p3);
        }
        public function init($p1, $p2, $p3) {
            //setup your object here
        }
    }
    

    then it is possible to construct the object and call

    $ob->init($p1, $p2, $p3);
    

    later.

提交回复
热议问题