请唠叨老大来解释一下,这两天为了这个问题快睡不着
从古代就有人表示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"
?>

解决方案 »

  1.   

    我的印象里面没有预包含这种说法。
    的确从古代就有人这么说,不过我验证的时候同你一样,发现根本不是这样。两者的区别可能只是在一个致命错误与否上。syre(神仙),你似乎经常就会说这句。
      

  2.   

    The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. 4.0.2以前的版本:
    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. 
      

  3.   

    既然是4.0.2以前的版本才会出现require所谓的总是试图包含文件,但是现在php早都过了5.0了,最普遍的也是4.3了,既然这样,我建议大家以后,见了谁说require是什么预包含什么玩意,大家都明确的告诉他,他是什么玩意,回他火星上去吧。
    这个问题,也不知道迷惑了多少新人,每当一有新人问到require和include时,这些人就大谈特谈预包含,可他们却不懂什么是预包含,看见他们不懂装懂,心里就很别扭。
    而且这些人还说我自以为是,天知道,我多方查证,却始终无法证实他们的观点,找不到例子来证明他们的观点。
    算了,就让他们那样认为下去吧。以前不是有人一直习惯用$name,而不用$_POST['name']这样的形式吗?如果不能接受新事物,就不要再与他们争论了。
      

  4.   

    require和include的区别在于
    require没有返回值
    而include有
      

  5.   

    最简单的证实方法。require一个不存在的文件时总是产生一个致命错误。
    以下代码不报错。
    exit;
    require("xxxxxx");