class FormHandler {
function validate(&$form, &$post) {
// first name required
if (!strlen($post->get (‘fname’))) {
$form[0] =& new Invalid($form[0]);
}
// last name required
if (!strlen($post->get(‘lname’))) {
$form[1] =& new Invalid($form[1]);
}
// email has to look real
if (!preg_match(‘~\w+@(\w+\.)+\w+~’
,$post->get(‘email’))) {
$form[2] =& new Invalid($form[2]);
}
}
}
class FormHandler {
// ...
function validate(&$form, &$post) {
$valid = true;
// first name required
if (!strlen($post- >get(‘fname’))) {
$form[0] =& new Invalid($form[0]);
$valid = false;
}
// last name required
if (!strlen($post->get (‘lname’))) {
$form[1] =& new Invalid($form[1]);
$valid = false;
}
214 The Decorator Pattern
// email has to look real
if (!preg_match(‘~\w+@(\w+\.)+\w+~’
,$post->get(‘email’))) {
$form[2] =& new Invalid($form[2]);
$valid = false;
}
return $valid;
}
}