分类: 系统运维
2011-03-17 21:39:33
用法:
include ("xxx.inc");
require ("xxx.inc");
include_once ("xxx.inc");
require_once ("xxx.inc");
区别和注意事项:
include 语句随时用到随时重新执行,require语句则是执行完一次之后,不再执行,仅应用结果。如果调用全局变量最好声明为全局变量 global 或者用 include,其实关键就是一个语法严谨性的问题。
include_once, require_once 用法同上。但是它们都会首先检查所要包含的文件是否已载入,如果已经载入了则不会重复载入,当然会影响到执行效率,不过是微乎其微的。
kecai_cale2011-03-17 22:23:37
NOTE: This function changed how it worked. In PHP 3 this behaved very differently than it does on PHP 4. Require used to include and parse the file regardless where the require line was positioned.
For example (PHP3):
<?php
if(false){ require_once 'file_does_not_exist.php'; }
?>
That code throw a fatal exception even though it's in a conditional block which evaluates to false. In PHP 4 t