当前位置:Gxlcms > PHP教程 > 这样判断不是引用文件?

这样判断不是引用文件?

时间:2021-07-01 10:21:17 帮助过:40人阅读

这样写的三个if句,不是引用文件 吧?我的理解是判断有没有,但不是引用!
如果不是引用的话,那这三个文件中的方法或设置啥的都没有引过来,比如它里面的函数或是变量常量啥的都没有引过来,还是不能用!不知这么理解对吗
if (!@include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');if (!@include(BASE_PATH.'/control/control.php')) exit('control.php isn\'t exists!');if (!@include(BASE_CORE_PATH.'/33hao.php')) exit('33hao.php isn\'t exists!');


回复讨论(解决方案)

是引用,判断有没有,有的话就引用进来了。

如果引用文件失败,则退出

是引用,判断有没有,有的话就引用进来了。


我卡就卡在这里,为啥它同时也是引用呢,这个道理怎么讲?

如果引用文件失败,则退出


可if条件成立也不能把文件引进来啊,因为我的理解它这里是判断真的假的,仅此而已。

为什么呢?
if (!@ include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');
include(dirname(dirname(__FILE__)).'/global.php') 用于引入 global.php 文件,这没有异议吧?
如果失败将返回假,并伴随错误信息。屏蔽掉错误信息后
var_dump(@include('global.php')); //bool(false)

这样还不能理解吗?

为什么呢?
if (!@ include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');
include(dirname(dirname(__FILE__)).'/global.php') 用于引入 global.php 文件,这没有异议吧?
如果失败将返回假,并伴随错误信息。屏蔽掉错误信息后
var_dump(@include('global.php')); //bool(false)

这样还不能理解吗?



为什么呢?
if (!@ include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');
include(dirname(dirname(__FILE__)).'/global.php') 用于引入 global.php 文件,这没有异议吧?
如果失败将返回假,并伴随错误信息。屏蔽掉错误信息后
var_dump(@include('global.php')); //bool(false)

这样还不能理解吗?


没有,我的理解是,这样只能是判断有没有,而不是引用文件。

那就请你动手做以下,以清除错误的想法

IF判断需要执行括号里的运算,include 执行完毕(成功)将返回1,SO

IF判断需要执行括号里的运算,include 执行完毕(成功)将返回1,SO


呵呵,对对,执行完毕,这个解释有道理,明白了。

include就是引用包含的意思啊,可以去看下手册,引用失败就退出。如果只是判断存不存用file_exists()就可以了。

人气教程排行