Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php require引发的错误不可见_Php_Include_Require - Fatal编程技术网

Php require引发的错误不可见

Php require引发的错误不可见,php,include,require,Php,Include,Require,我正在阅读php中include和require之间的区别 我用php创建了一个测试文件,以更好地了解差异,但它们都没有显示任何内容(我在require中没有看到任何错误) 请帮帮我。谢谢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.

我正在阅读php中include和require之间的区别

我用php创建了一个测试文件,以更好地了解差异,但它们都没有显示任何内容(我在
require
中没有看到任何错误)

请帮帮我。谢谢

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
for( $value = 0; $value < 10; $value++ )
if($value>10)
require("boom.php"); // no such file exits in real
?>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    for( $value = 0; $value < 10; $value++ )
    if($value>10)
    include("boom.php"); // no such file exits in real
    ?>
    </body>
    </html>

无标题文件
无标题文件

您的PHP可能已关闭显示错误,这意味着您将不会在客户端输出中看到错误消息。您应该在开发环境的php.ini中启用此设置

如果你有这样的东西,你至少会看到失败:

<html>

<body>
<p>Before require</p>
<?php require('does-not-exist'); ?>
<p>After require</p>
</body>

</html>

在要求之前

要求后

有了一些实际的输出,您会看到只有“before require”文本被输出-当
require()
失败时,脚本将终止执行


对于您的版本,您没有可见的输出,必须查看浏览器中的页面源代码,才能看到没有

可能您的PHP已关闭显示错误,这意味着您将不会在客户端输出中看到错误消息。您应该在开发环境的php.ini中启用此设置

如果你有这样的东西,你至少会看到失败:

<html>

<body>
<p>Before require</p>
<?php require('does-not-exist'); ?>
<p>After require</p>
</body>

</html>

在要求之前

要求后

有了一些实际的输出,您会看到只有“before require”文本被输出-当
require()
失败时,脚本将终止执行


对于您的版本,您没有可见的输出,必须查看浏览器中的页面源代码,以查看是否没有显示错误。您可以通过调用
phpinfo()
来检查这一点

设法安置

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
在脚本开始时,直接在屏幕上显示错误(仅建议用于开发系统)


编辑Doh!我同意达米恩的回答。

可能
显示错误
被禁用。您可以通过调用
phpinfo()
来检查这一点

设法安置

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
在脚本开始时,直接在屏幕上显示错误(仅建议用于开发系统)


编辑Doh!我同意Damien的回答。

您的测试代码是错误的,
$value
永远不会大于10。尝试此操作,您将出现致命错误

<?php
require("boom.php"); // no such file exits in real
?>

您的测试代码错误,
$value
永远不会大于10。尝试此操作,您将出现致命错误

<?php
require("boom.php"); // no such file exits in real
?>


谢谢。我做到了,我发现require及时给了我一个错误,include给了我10次错误。它们之间的区别现在变得越来越模糊。include不应该给出错误。include会给您一个警告,但不要停止页面的执行。谢谢。我做到了,我发现require及时给了我一个错误,include给了我10次错误。它们之间的区别现在变得越来越模糊。include不应该给出错误。include会给您一个警告,但不要停止页面的执行。