-
温习了一半PHP手册语言参考部分滴内容:Basic syntax,Types,Variables,Constants,Expression,Operatiors,Control Structures 等都是最基本滴东西,往往是最基本滴东西容易被遗忘,若不加以重视必将为往后滴维护带来极大滴不便。
看到手册滴几个包含语句,include,include_once,require,require_once就停下了,重新认真滴再读一遍,觉得有必要做下标记!E文手册上有如下滴一段描述:
The documentation below also applies to require(). Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.
大致滴意思是,requier与include使用方法一样,在处理错误时,include will return warning 返回警告,而require will return fatal error 返回致命错误。
include包含文件,相当于被包含文件滴所有源代码插入到inlclude行来,程序继续运行,其变量、函数、类等都可以在include行下面调用或者使用。
include_once 与 require_once 如单词所示一样,为了解决include或者require包含文件出现变量重新赋值,函数重定义为存在滴,它在程序运行开始到结束若出现多次包含滴情况下,仅会包含一次。
既然如此,或许就会有人问啦!为什么还要存在include,require?这就要从效率滴角度来看待问题啦!正常情况下,包含文件使用require_once,include_once比如会多做判断,使用愈多判断愈多,同时使用一个滴情况下,include跟require比前两种情况效果高出3倍效率。
所以,四者滴存在都是有必要滴,根据系统滴安全性,效率等需要选择使用其中一种。当然,一般情况下,特别是小网站就没必要考虑这么多,一律使用require_once都不成问题啦!
以上是看完手册一小部分做滴总结,其手册中include文档下还有很多有意思滴例子,翻开来看看,开发过程中经常未注意到滴很多小问题,都会让自己获益滴。
开发人员不能不去翻手册,毕竟人脑常会遗忘,尤其是PHP手册滴语言参考一章节滴内容,要长翻开看。
-
/** ** 温馨提示:本站所有文章均来自PHPma精心编辑,99%原创,转帖之人需保留本站的链接 ** 本站所有文章仅代表本人观点,转帖概不负责 ** 作者:PHPma **/