<?php
require_once 'demo1.php';
require_once 'demo1.php';
require_once 'demo1.php';
?>
output
e10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359s
7.3.5 include与require的区别
Include后面如果还有其他代码,当调用include出错时,后面的代码还会继续执行,但是require则不会。
Include在调用一个不存在的文件时,会给出警告,但是会继续执行后面的代码。
复制代码 代码如下:
<?php
include 'demo111.php';
echo('this is demo13.php');
?>
output
Warning: include(demo111.php) [function.include]: failed to open stream: No such file or directory in D:\AppServ\www\Basic7\demo13.php on line 2
Warning: include() [function.include]: Failed opening 'demo111.php' for inclusion (include_path='.;C:\php5\pear') in D:\AppServ\www\Basic7\demo13.php on line 2
this is demo13.php
Require在调用一个不存在的文件时,会给出一个错误,并中止代码的执行。
复制代码 代码如下:
<?php
require 'demo111.php';
echo('this is demo14.php');
?>
Output
Warning: require(demo111.php) [function.require]: failed to open stream: No such file or directory in D:\AppServ\www\Basic7\demo14.php on line 2
Fatal error: require() [function.require]: Failed opening required 'demo111.php' (include_path='.;C:\php5\pear') in D:\AppServ\www\Basic7\demo14.php on line 2
7.4.魔法常量
名称
描述
_FILE_
当前文件名
_LINE_
当前行号
_FUNCTION_
当前函数名
_CLASS_
当前类名
_METHOD_
当前方法名
所谓的魔法常量,并不是真的常量,而是根据场合去获取固定值的变量
复制代码 代码如下:
<?php
echo __FILE__;
echo '<br>';
echo __LINE__;
echo '<br>';
function funcTest()
{
echo __FUNCTION__;
}
funcTest();
?>
output
D:\AppServ\www\Basic7\demo15.php
5
funcTest
您可能感兴趣的文章: