【问题标题】:PHP isset not works on $this variablePHP isset 不适用于 $this 变量
【发布时间】:2020-04-18 22:40:18
【问题描述】:

我想弄清楚为什么 isset 不适用于 $this 变量?我正在使用 HMVC codeigniter 并尝试检查模块是否加载成功:

$this->load->module('welcome'); var_dump(isset($this->welcome)); print_r($this->welcome);

结果是:

bool(false) --- This is the result of isset. Below is result of var_dump
Welcome Object
(
    [autoload] => Array
        (
        )

    [load] => MY_Loader Object
        (
            [_module:protected] => welcome
            [_ci_plugins] => Array
                (
                )

            [_ci_cached_vars] => Array
                (
                )

            ... some other protected variables

            [controller] => Welcome Object
 *RECURSION*
        )

)

为什么 isset 返回 false?

【问题讨论】:

  • 试试 !empty() ,它适用于 isset 和 empty。
  • 使用此代码:var_dump(empty($this->nonexisting)); 返回 true,即使它不存在 @AhmedSunny
  • 看看[this](php.net/manual/en/types.comparisons.php)了解一下

标签: php codeigniter-3 isset hmvc


【解决方案1】:

在深入检查 CodeIgniter 核心文件后,我发现有一种方法可以检查它:

        if(!isset(Modules::$registry['welcome'])) { // check module loaded
            return jsonError(2);
        }

        // module loaded. Go ahead

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 2013-07-12
    相关资源
    最近更新 更多