我不确定我是否理解 properties() 方法正确它从 $db_table_fields 中提取值并将它们作为数组 $properties 中的键并将它们分配为同一数组的值...?
不想只是复制/粘贴代码试图理解它..
class User{
protected static $db_table = "users";
protected static $db_table_fields = array('username','password','first_name','last_name');
public $id;
public $username;
public $password;
public $first_name;
public $last_name;
protected function properties(){
$properties = array();
foreach(self::$db_table_fields as $db_field ){
if(property_exists($this,$db_field)){
$properties[$db_field] = $this->$db_field;
}
}
return $properties;
}
}