2013-11-04 58 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

不客气,先生。如果这是正确的答案,请将其标记为已接受:-) –