//php 5.6
class father{
public function __construct() {
  echo __METHOD__;
  }
}

class son extends father{
//public function __construct() {
  // parent::__construct();
  // echo __METHOD__;
//}

//方法名同类名相同如果没有__construct,会被当做构造函数。如果被当做构造函数,没有parent::__construct();父类的构造函数照样不执行
public function son() {
  //parent::__construct();
  echo __METHOD__;
  }
}

$a=new son();

相关文章:

  • 2022-01-26
  • 2021-09-30
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2021-12-03
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案