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

查看:226
本文介绍了在写上下文中不能使用方法返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下if条件导致错误:

The following if condition is causing an error:

if( !empty ($this -> session -> userdata( 'user_id') ) )
{
    $user_id = $this -> session -> userdata( 'user_id' );
} 
else 
{ 
    $error = "ID doesn't exist";
}

我收到以下错误:

Fatal error: Can't use method return value in write context in (line number)

$

推荐答案

替换第一个如果 if(!$ this-> session-> userdata('user_id'))语句

Replace the first if statement with if( ! $this->session->userdata('user_id') ).

empty 函数检查变量是空的,但 userdata 是一个函数。此外,根据 CodeIgniter文档中的信息, userdata 函数返回 FALSE 如果项目不存在,这意味着如果 user_id 不存在您的会话, else 中的代码将被执行。

The empty function check if a variable is empty but userdata is a function. Additionally, for your information, according to the CodeIgniter documentation, the userdata function returns FALSE if the item doesn't exist, which means that if user_id doesn't exist in your session, the code in the else will be executed.

这篇关于在写上下文中不能使用方法返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆