I have a data processor class which can only perform its primary function once all its member variables have been assigned a value:
class {
public $firstName;
public $lastName;
public $ssn;
public $accessKey;
public function __construct($data = null) {
if (is_array($data)) {
// Assign the value of any fields in $data to
// the corresponding member var
}
}
public processData() {
// *** CHECK IF ALL PROPERTIES HAVE VALUES ***
foreach ($this as $p=>$val) {
if ($val === null) {
return false;
}
}
doStuff();
}
}
Is there a more efficient or elegant way to verify that all properties have a value? It feels kind of PHugly to do it this way.