0

このクラスの作成を開始しました。ユーザーを登録したいと思います。

<?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!');
    }
}

私はそれを次のように呼びます:

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

なぜそれが返されるのSuccessですか?やったarray_push

4

1 に答える 1

3
class User {

    // ...

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

$userからオブジェクトを返すのを忘れましたregister()

于 2013-11-04T19:54:32.547 に答える