请唠叨老大来解释一下,这两天为了这个问题快睡不着
从古代就有人表示require是预处理包含,include是包含,他们称require只是预包含了,并不代表包含了(我相信他们也是听别人说的,同样糊里糊涂的)
他们拿不出任何有效的证据来表明require是包含了,但是却不能在这个文件中显示中内容举例吧:他们的观点是同样包含了2.php,只是预包包含了。我的疑问是既然包含了2.php,那为什么2.php的内容"2"没有输出呢?
//test.php
<?
if(1)
require 1.php //1.php的内容为字符串"1"
else
require 2.php //2.php的内容为字符串"2"
?>
从古代就有人表示require是预处理包含,include是包含,他们称require只是预包含了,并不代表包含了(我相信他们也是听别人说的,同样糊里糊涂的)
他们拿不出任何有效的证据来表明require是包含了,但是却不能在这个文件中显示中内容举例吧:他们的观点是同样包含了2.php,只是预包包含了。我的疑问是既然包含了2.php,那为什么2.php的内容"2"没有输出呢?
//test.php
<?
if(1)
require 1.php //1.php的内容为字符串"1"
else
require 2.php //2.php的内容为字符串"2"
?>
的确从古代就有人这么说,不过我验证的时候同你一样,发现根本不是这样。两者的区别可能只是在一个致命错误与否上。syre(神仙),你似乎经常就会说这句。
Prior to PHP 4.0.2, the following applies: require() will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once.
这个问题,也不知道迷惑了多少新人,每当一有新人问到require和include时,这些人就大谈特谈预包含,可他们却不懂什么是预包含,看见他们不懂装懂,心里就很别扭。
而且这些人还说我自以为是,天知道,我多方查证,却始终无法证实他们的观点,找不到例子来证明他们的观点。
算了,就让他们那样认为下去吧。以前不是有人一直习惯用$name,而不用$_POST['name']这样的形式吗?如果不能接受新事物,就不要再与他们争论了。
require没有返回值
而include有
以下代码不报错。
exit;
require("xxxxxx");