0

我正在学习 OOP 技术,所以如果我的问题听起来太基本,请不要太苛刻 ^_^ 我有 4 个 php 文件。

index.php
parentClass.php
childClass1.php
childClass2.php

childClass1.php 和 childClass2.php 基本上扩展了 parentClass.php。所以我的问题是,如果我在索引文件中包含或需要两个子类,index.php 文件是否会调用 parentClass 两次?例如:

require_once("childClass1.php");
$child1 = new childClass1();
require_once("childClass2.php");
$child2 = new childClass2();
4

1 回答 1

5

这取决于如何parentClass.php加载。

除非您使用require_onceinclude_once文件将被包含多次,否则将导致致命错误,因为每个类只能定义一次。

如果您使用的是自动加载器,则该文件只会被包含一次,因为它只会加载未知的类。

于 2013-06-03T08:21:06.353 回答