简体   繁体   English

PHP-如果我们在php中创建子类的对象,它会调用父类构造函数,然后调用子类构造函数(如java)吗?

[英]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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Java中,您可以通过父类的子类的构造函数调用父类的超类构造函数吗? - In Java, can you call a parent class's superclass constructor through the constructor of the child class of the parent class? Java:子类构造函数类如何中和父构造函数? - Java: How Can be child class constructor class neutralize parent constructor? 在Java中的子类中使用父构造函数 - Using parent constructor in a child class in Java 为带有父对象的子类编写Java构造函数 - Writing Java constructor for child class that takes parent object 在.NET中,父类的构造函数是否将其子类的构造函数称为第一件事? - In .NET, does a parent class' constructor call its child class' constructor first thing? java构造函数访问(如果子类中有私有构造函数) - java constructor accessing (if we have private constructor in child class) 为什么对父 class 构造函数的调用不调用在子 class 中覆盖的父方法? - Why does the call to a parent class constructor not call the parent's methods that are overriden in the child class? 声明一个Java对象但调用子类的构造函数 - Declaring a Java object but calling the constructor of a child class Java:如何在子类构造函数中调用超类构造函数? - Java: How does a call to the super class constructor inside of a child class constructor work? Java父类未调用Scala子类构造函数 - Scala Child Class Constructor is not being called from Java Parent Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM