我有一些代码为每个环境启用或禁用基于某些标准的APC。所有操作都很好,但是当我以相反的顺序复制和粘贴一些if语句时,我得到了一个未知的PHP错误,没有任何逻辑。我有PHP 5.5.7,脚本在CLI模式下运行。
// Works fine
$test = ( function_exists('apc_fetch') || ini_get('apc.enabled') );
// Fail with "Call to undefined function function_exists()"
$test = ( ini_get('apc.enabled') || function_exists('apc_fetch') );
// Works fine because true do lazy check in OR
$test = ( true || function_exists('apc_fetch') );
// Fail with "Call to undefined function function_exists()"
$test = ( false || function_exists('apc_fetch') );有人能解释吗?太好奇了。
当前的解决方案是将function_exists('apc_fetch')放在OR检查的第一个位置,但这不是一个解决方案.
编辑:@dev-null居民得到了诀窍,问题是用一个非unicode字符来表示在function_exists()之间的空间。
发布于 2013-12-30 13:25:32
我测试了这段代码
<?php
$test = ( false || function_exists('apc_fetch') );
var_dump($test);
?>得到了这个输出
bool(false)所以这对我有用..。有些奇怪的事情发生了..。你能试试这个吗?
$test = ( !function_exists('apc_fetch') && ini_get('apc.enabled') );还是这个?
$test = ( false || ( function_exists('apc_fetch') ) );https://stackoverflow.com/questions/20840293
复制相似问题