我有一个这样的类定义:
class User{
public $first;
public $last;
public $email;
public $guid;
public $website;
public $bio;
public $picture;
public $gender;
...
}
和一个构造函数,它从工厂函数中获取值并将它们放入类中,如下所示:
public function __construct($guid, $first , $last,$email, $bio, $picture, $gender) {
$this->guid = $guid;
$this->first = $first;
$this->last = $last;
$this->email = $email;
...
}
是否有一种简单的方法可以自动分配所有这些变量?或者我可以使用带有 PHP 参数函数的 for 遍历它们吗?