Possible Duplicate:
PHP - Initialize object members with array parameter
I am looking for a way to have my class apply data from an associative array to its own member variables. However, if those variables do not exist, the process should not throw any errors.
Please note: i am either not looking for what the extract() function does or i misunderstand its behaviour.
Example:
class customer {
public $firstName;
public $lastName;
public $email;
public function apply($data){
/* here i want to be able to iterate through $data and set the class
variables according to the keys, but without causing problems
(and without creating the variable in the class) if it does not exist
(yet)) */
}
}
$c=new customer();
$c->apply(array(
'firstName' => 'Max',
'lastName' => 'Earthman',
'email' => '[email protected]'
));
Hope the description is proper.
Please ask if anything is unclear.
catchthe exception for a missing attribute?