Okay, but inside the object, how are all the items stored? As an example, here's something very short:
<?php
class Employer {
var $emp; // To hold the object values...
var $attributes; // To hold what attributes are valid
var $errors; // To hold errors....
function __construct() {
$this->emp = array();
$this->attributes = array('name', 'age', 'sex', 'department', 'address');
}
function setAttribute($name, $val=null) {
if(is_array($name)) {
foreach($name as $key=>$val) {
if(in_array($key, $this->attributes)) { $this->emp[$key] = $val; }
else { $this->errors[] = $key . ' is not an allowed attribute.'; }
}
}
if(!in_array($name, $this->attributes)) { return false; }
else
$this->emp[$name] = $val;
return true;
}
function getAttribute($name) {
if(!in_array($name, $this->attributes)) { return 'Unavailable attribute "' . $name . '"'; }
if(!key_exists($name, $this->emp)) { return 'Unknown attribute "' . $name . '"'; }
return $this->emp[$name];
}
}
// Instantiate a new Employer object:
$Emp = new Employer();
$Emp->setAttribute('name', 'bpat1434');
$Emp->setAttribute('sex', 'Male');
$Emp->setAttribute('department', 'PHPBuilder');
$Emp->setAttribute('age', '23');
$Emp->setAttribute('address', '123 Memory Lane');
// Get any one of the attributes....
echo $Emp->getAttribute('name');
echo '<hr>';
// Reset the attributes to something else...
$Emp->setAttribute(array('name'=>'knapsack3', 'age'=>'Unknown', 'sex'=>'Unknown', 'address'=>'PHPBuilder :: General Help', 'department'=>'PHP'));
// Get one of the new attributes...
echo $Emp->getAttribute('name');
?>
That works. I hope that example is enough for you.