PHP构造函数__construct()的说明
作者:Aliot
发布时间:2019-12-17
评论:0
阅读:20
__construct()
在php类的继承中,如果父子类都定义了__construct()方法,则在实例化子类时,只调用子类的__construct()
如果父类定义了__construct(),而子类没有定义,则实例化子类时,默认调用父类的__construct(),如果子类不想要父类调用__construct(),则子类必须自己定义自己的__construct()
如果子类定义了自己的__construct(),同时还是调用父类的__construct(),则在子类的__construct()中可以写parent::__construct()