Verify方法返回true

I am trying to verify whether the method in my class is returning a true value. Please look at my object below the class and tell me if it is a valid statement. I am using this to verify whether an email address already exists in the database.

My class and it's constructor

class CheckEmail {

public function __construct($email) {

$db = Database::GetHandler();

    $sql = "SELECT email from users WHERE email='$email'";
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $rows = $stmt->rowCount();

    if($rows > 0) {

        return true;

    } else {

        return false;
    }
}

}

My object from this class:

if($checkEmail = new CheckEmail($_POST[email])==true) {...

Constructors cannot return a value, that doesn't make any sense. Constructors are there to create (and return) an object of its class.

You should make another function to do this check, and then call that.

class CheckEmail {

    public function check($email) {
        $db = Database::GetHandler();

        $sql = "SELECT email from users WHERE email='$email'";
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $rows = $stmt->rowCount();

        if($rows > 0) {
            return true;
        }
        else {
            return false;
        }
    }
}

(P.S. You can just do return $rows > 0;)

And then you can call it like this:

var $email = new CheckEmail;
if($email->check($_POST[email]) === TRUE){
// or just if($email->check($_POST[email])){

Thing is, do you really need a class here? You could just declare the CheckEmail function normally, and not in its own class.

Constructors do not return a value. You need a different approach. http://www.php.net/manual/en/language.oop5.decon.php

Try putting

$checkEmail = new CheckEmail($_POST[email]);

Before the if statement, then

If($checkEmail) {...