2013-11-04 57 views
0

我已經開始建立這個類的,我想註冊一個用戶:爲什麼它返回SuccessPHP變化的變量

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

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

我這樣稱呼它?我做過array_push

+3

你沒有返回任何東西在'註冊()' – jprofitt

回答

3
class User { 

    // ... 

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

你忘了從register()返回$user對象。

+0

哦謝謝!我看不到它 – HtmHell

+0

不客氣,先生。如果這是正確的答案,請將其標記爲已接受:-) –