PHP返回值不一致:true变为false

时间:2014-01-30 02:07:26

标签: php boolean

我在PHP中遇到了一个非常奇怪的问题。这种行为让我觉得这是一个错误,但它是如此根本,它真的不应该。

在其他代码中,我有这两个函数:

// Check admin authentication
// Used to check user has access to a page
function function_check_admin(){
    function_start_session();

    $isadmin = function_is_admin(NULL);
    error_log("got return of ".intval($isadmin)." which is of type ".gettype($isadmin));
    $isnotadmin = !(function_is_admin());
    if($isnotadmin){
        echo echo_error("You are not authorised to access this page.");
        exit;
    }
}

...

// Check if user is an administrator
// pass access parameter if access already loaded and known
function function_is_admin($access = NULL){
    if (!function_is_logged_in()){
        return False;
    }

    // Load access
    if ($access === NULL)
        $access = account_access();

    error_log("access is ".$access);
    $return = ($access <= ADMIN);

    error_log("admin is ".$return);
    return $return;
}

有时,当调用function_check_admin()时,它会抛出错误并退出。错误日志报告:

[error] access is 0
[error] admin is 1
[error] got return of 0 which is of type boolean, referer: ...

此外,如果我更换

    return $return;

    return TRUE;

行为和错误日志保持不变。返回值true在调用函数中突然变为false。

问题只会偶尔出现。完全相同的代码在网站的开发副本上完全正常。

最奇怪的是,当它发生时,可以通过删除与该网站相关的所有cookie来修复它。

我正在运行PHP 5.3.3(cli)(内置:2013年8月19日05:50:20)

这有什么优先权吗?任何想法可能会发生什么,以及解决方法是什么?

0 个答案:

没有答案
相关问题