After upgrade of Codeigniter i get this message
Cannot access protected property 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 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
or is if ($CI->load->get_var($key))) {
check enough?
You cannot use isset
on a function
ie $CI->load->get_var($key)
will always return "something" - but what that "something" is depends.
So you are correct - the code below will achieve your goal. If the function returns "null" - then isset already failed. If the function returns something else (besides null) - then you will have a valid return.
if ($CI->load->get_var($key)) != null) {
$val = $CI->load->get_var($key);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.