0

I have started to build this class, and I want to register a user:

<?php
class User {
    protected $_id;
    protected $_name;
    protected $_email;
    protected $_password;
    public $isLogged = false;
    public $errors = array();

    public function __construct() {

    }
    public static function register($username,$email,$password,$captcha,$agree) {
        $user = new self;
        array_push($user->errors,'Error!');
    }
}

I call it like this:

$user = User::register($_POST['username'],$_POST['email'],$_POST['password'],$captcha,$agree);
if(empty($user->errors)) {
    echo 'Success';
} else {
    echo 'Failed';
}

Why does it returns Success? I did array_push!

1
  • 3
    You didn't return anything in register() Commented Nov 4, 2013 at 19:53

1 Answer 1

3
class User {

    // ...

    public static function register($username,$email,$password,$captcha,$agree) {
        $user = new self;
        array_push($user->errors,'Error!');
        return $user;
    }
}

You forgot to return the $user object from register().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.