Home  >  Article  >  Backend Development  >  关于php的include的一道面试题?该如何处理

关于php的include的一道面试题?该如何处理

WBOY
WBOYOriginal
2016-06-13 13:43:59845browse

关于php的include的一道面试题?

以下代码能正常执行吗?如果能 会有什么问题?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
 if($condiation)
   include('a.php');
 else
   require_once('b.php');



不知道求解答

------解决方案--------------------
include()会产生一个警告,而require()则导致一个致命的错误(出现错误,脚本停止执行)++

------解决方案--------------------
include和include_once两个如果请求不到文件会报warning
程序还会继续执行
可以用在ifelse语句中
而require和require_once不同 如果请求不到文件会发生致命错误.并且脚本终止执行
并且无论require_once和require是否能够得到执行权限.在实际中写有require和require_once的代码行都会被执行.这个和PHP的执行机制有关系.
所以上面的代码.能够执行.执行的结果就是
条件成立的情况下如果请求道a.php和b.php那么不会报错.如果请求到a.php但没有b.php会报致命错误.如果请求到b.php而没有请求到a.php那么会报警告.如果两个文件都不存在.会报警告和致命错误.
如果条件不成立
效果类似上面只是没有警告了.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn