require()函数和include()函数的区别
时间:2008-07-14 来源:lvDbing
require()和include()区别
require()函数和include()函数作用都是“包括并运行指定文件”,但“怎样处理失败”两者各有不同的作法。
require()函数,当“包括并运行指定文件”错误时,则导致一个“致命的错误”,也就是程序中止了运行,(Error)。
include()函数,当“包括并运行指定文件”错误时,则导致一个“警告的错误”,也就是程序还继续运行,(Warning)。
require()函数
require()函数,引用指定文件错误的例子和返回的错误代码。
html>
head>
title>Test Program/title>
/head>
body>
?
require("1234.txt");
echo "Hello World";
?>
/body>
/html>
Warning: require(1234.txt) [function.require]: failed to open stream: No such file or directory in C:\AppServ\www\test\index.php on line 7
Fatal error: require() [function.require]: Failed opening required '1234.txt' (include_path='.;C:\php5\pear') in C:\AppServ\www\test\index.php on line 7 //致命错误,程序中止运行
include()函数
include()函数,引用指定文件错误的例子和返回的警告代码。
html>
head>
title>Test Program/title>
/head>
body>
?
include("1234.txt");
echo "Hello World";
?>
/body>
/html>
Warning: include(1234.txt) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\test\index.php on line 7
Warning: include() [function.include]: Failed opening '1234.txt' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\test\index.php on line 7 //错误警告,程序继续运行
Hello World
require()函数和include()函数作用都是“包括并运行指定文件”,但“怎样处理失败”两者各有不同的作法。
require()函数,当“包括并运行指定文件”错误时,则导致一个“致命的错误”,也就是程序中止了运行,(Error)。
include()函数,当“包括并运行指定文件”错误时,则导致一个“警告的错误”,也就是程序还继续运行,(Warning)。
require()函数
require()函数,引用指定文件错误的例子和返回的错误代码。
html>
head>
title>Test Program/title>
/head>
body>
?
require("1234.txt");
echo "Hello World";
?>
/body>
/html>
Warning: require(1234.txt) [function.require]: failed to open stream: No such file or directory in C:\AppServ\www\test\index.php on line 7
Fatal error: require() [function.require]: Failed opening required '1234.txt' (include_path='.;C:\php5\pear') in C:\AppServ\www\test\index.php on line 7 //致命错误,程序中止运行
include()函数
include()函数,引用指定文件错误的例子和返回的警告代码。
html>
head>
title>Test Program/title>
/head>
body>
?
include("1234.txt");
echo "Hello World";
?>
/body>
/html>
Warning: include(1234.txt) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\test\index.php on line 7
Warning: include() [function.include]: Failed opening '1234.txt' for inclusion (include_path='.;C:\php5\pear') in C:\AppServ\www\test\index.php on line 7 //错误警告,程序继续运行
Hello World
相关阅读 更多 +