未初始化的字符串偏移量:0,为什么


Uninitialized string offset: 0, why?

<< Error message >>
Severity: Notice
Message: Uninitialized string offset: 0
Filename: controllers
Line Number: 192

这是我遇到的错误消息。 下面是控制器和模型文件。

// controller file
    $user = $this->user_model->getByMail(array('total_mail' => $mail_auth));
    if($user = '') 
    {
        $this->load->helper('url');
        redirect('/');
    }
    else if($this->encrypt->decode($user['password']) == $password_auth) // line 192
    {
        if($user['verified'] == 'N')
        {
            $this->session->set_flashdata('message', 'Wront inputs.');
            $this->load->helper('url');
            redirect('/');
        }
    }
    else
    {
        $this->session->set_flashdata('message', 'Wrong inputs');
        $this->load->helper('url');
        redirect('/');
    }
}
    // model file
function getByMail($option)
{
    $basic_result = $this->db->get_where('ndd_user', array('total_mail' => sanitizeMySQL($option['total_mail'])));
    if ( $basic_result->num_rows() > 0 )
    {
        $result = $basic_result->row_array();
        return $result;
    }
    else
    {
        return '';
    }
}

在模型文件中有一个 getByEmail 函数,它输出查询结果数组。但是,它犯了错误。我该怎么办?

提前致谢:)

你分配if($user = '')

至少必须是

if($user == '') 

在代码中的某个地方,您尝试在测试字符串为空之前获取某个字符串的第一个字符(或者你想用作数组,而它不是,但这首先会引发警告(

$foo = '';
// these throws "Notice: Uninitialized string offset: 0"
$firstChar = $foo[0];
$firstChar = $foo{0};
// this throws "Warning: Illegal string offset 'bar'"
// and "Notice: Uninitialized string offset: 0"
$bar = $foo['bar'];