函数只返回FALSE


Function returning only FALSE

我有一个php函数。

                if ( $this->input->post('email') == $this->_email($this->input->post('email')) )
            {
                $this->_data['error'] = 'Email exist!';
                return $this->load->view('login/template_view', $this->_data);
            }

即使相等为真,我的函数也只返回FALSE。我使用debug来查看我的函数是否可以返回TRUE。

bool(false) string(14) "alex@yahoo.com" object(stdClass)#25 (1) { ["email"]=> string(14) "alex@yahoo.com" }

我有两个字符串,第一个是返回alex@yahoo.com,并且第二个字符串正在返回alex@yahoo.com...但如果条件仍然返回FALSE。

我的功能出了什么问题?

调试:

                var_dump($this->input->post('email'));
                var_dump($this->_email($this->input->post('email')));
                die();

您正在将字符串与对象进行比较。为了进行比较,您需要将字符串与对象的email属性进行比较。可以使用->或方法访问对象特性。

您可以在这里和这里阅读更多关于PHP对象的信息。

为了让你的代码工作,替换:

if ( $this->input->post('email') == $this->_email($this->input->post('email')) )

带有

if ( $this->input->post('email') == $this->_email($this->input->post('email'))->email )