简体   繁体   中英

PHP -If we create object of child class in php, does it call parent class constructor and then child class constructor like java?

PHP-如果我们在php中创建子类的对象,它会调用父类构造函数,然后调用像Java这样的clild类构造函数吗?

No, you need to call the parent constructor in child class.

public function __construct() {
  parent::__construct();
  //...other code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM