PHP从静态函数更改变量
我已经开始构建此类,我想注册一个用户:PHP从静态函数更改变量,php,class,oop,static,Php,Class,Oop,Static,我已经开始构建此类,我想注册一个用户: <?php class User { protected $_id; protected $_name; protected $_email; protected $_password; public $isLogged = false; public $errors = array(); public function __construct() { } public st
<?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\u push
class User {
// ...
public static function register($username,$email,$password,$captcha,$agree) {
$user = new self;
array_push($user->errors,'Error!');
return $user;
}
}
您忘记从register()
返回$user
对象
您忘记从register()
返回$user
对象
您忘记从register()
返回$user
对象
您忘记从
register()
返回$user
对象register()
中没有返回任何内容register()
中没有返回任何内容register()
中没有返回任何内容register()
class User {
// ...
public static function register($username,$email,$password,$captcha,$agree) {
$user = new self;
array_push($user->errors,'Error!');
return $user;
}
}