简体   繁体   English

codeigniter无法访问受保护的属性MY_Loader :: $ _ ci_cached_vars

[英]codeigniter Cannot access protected property MY_Loader::$_ci_cached_vars

After upgrade of Codeigniter i get this message 升级Codeigniter后,我收到此消息

Cannot access protected property MY_Loader::$_ci_cached_vars 无法访问受保护的属性MY_Loader :: $ _ ci_cached_vars

i know that this property is now protected so i change 我知道此属性现在受到保护,所以我更改了

else if (isset($CI->load->_ci_cached_vars[$key]))
    {
        $val = $CI->load->_ci_cached_vars[$key];
    }

to

if (isset($CI->load->get_var($key)))
    {
        $val = $CI->load->get_var($key);
    }

but then i get 但后来我明白了

Can't use method return value in write context 在写上下文中不能使用方法返回值

this is get_var method 这是get_var方法

/**
     * Get Variable
     *
     * Check if a variable is set and retrieve it.
     *
     * @param   array
     * @return  void
     */
    public function get_var($key)
    {
        return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
    }

what can i do, just use 我该怎么办,只需使用

if ($CI->load->get_var($key)) != null)  {
        $val = $CI->load->get_var($key);
    }

without isset? 没有烦恼? i want to check if is not NULL, becouse get_var method return null 我想检查是否不为NULL, get_var方法返回null

or is if ($CI->load->get_var($key))) { check enough? 还是if ($CI->load->get_var($key))) {检查是否足够?

You cannot use isset on a function 您不能在函数上使用isset

ie $CI->load->get_var($key) will always return "something" - but what that "something" is depends. $CI->load->get_var($key)将始终返回“某物”-但是该“某物”取决于什么。

So you are correct - the code below will achieve your goal. 因此,您是正确的-以下代码将实现您的目标。 If the function returns "null" - then isset already failed. 如果函数返回“ null”-那么isset已经失败。 If the function returns something else (besides null) - then you will have a valid return. 如果函数返回其他值(除null外)-那么您将获得有效的返回值。

if ($CI->load->get_var($key)) != null)  {
        $val = $CI->load->get_var($key);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM