我正在学习OOP技术,所以如果我的问题听起来太基本,请不要太苛刻^ _ ^我有4个php文件.
index.php
parentClass.php
childClass1.php
childClass2.php
Run Code Online (Sandbox Code Playgroud)
childClass1.php和childClass2.php基本上扩展了parentClass.php.所以我的问题是,如果我在索引文件中包含或要求两个子类,index.php文件是否会调用parentClass两次?例如:
require_once("childClass1.php");
$child1 = new childClass1();
require_once("childClass2.php");
$child2 = new childClass2();
Run Code Online (Sandbox Code Playgroud)
这取决于如何parentClass.php加载.
除非您使用require_once或include_once文件将被多次包含,否则将导致致命错误,因为每个类可能只被定义一次.
如果您使用自动加载器,该文件将只包含一次,因为它只会加载未知类.
| 归档时间: |
|
| 查看次数: |
109 次 |
| 最近记录: |