考虑以下内容:
class MyClass {
public static function MyIncludingMethod() {
include_once("includes.php");
}
public static function MyOtherMethod() {
}
}
假设这是有效的,includes.php什么时候会被包含?
选项1)当包含所有这些的php文件包含时
选项2)当MyClass::MyIncludengMethod()被调用时
选项3)当调用MyClass中的任何内容时,即使MyClass::MyIncludingMethod()尚未调用
includes.php:
<?php
touch('i_was_called.txt');
?>
结果
- 否
- 是
- 否
一切如预期:)