Hi. I have this code from a class.
class User {
protected $data=array(
'id'=>null,
'username'=>null,
'passwrd'=>null,
'email'=>null,
'lastAccess'=>null,
'firstname'=>null,
'lastname'=>null,
'active'=>null,
'type'=>null,
'hash'=>null
);
public function __construct() { }
public static function assemble(array $data) {
foreach ($data as $n=>$v) {
$userObj=new User();
if (in_array($n,array_keys($userObj->data))) {
$userObj->data[$n]=$v;
}
}
var_dump($userObj);
die();
return $userObj;
}
}
The "assemble" function it's used in this way in my program : $userObj=User::assemble($_POST). Its purpose is to construct an User object with the values fetched from the array i pass as a parameter.
I get no error during execution, but the function doesn't do its job.
Can you tell me how to fix the code in order to work?
EDIT: The problem was that i instantiated the User object inside the foreach loop. It's figured it out now, so if it's possible please delete this post.