411 REFERENCE · Wikibooks
PHP Programming/OOP5/Input validation
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
PHP Programming
This is an example using the power of OOP with PHP5. This example can be used to validate different user inputs.
This was moved by Wykis from Kgrsajid's example on Programming:PHP.
interface Validator
{
public function validate($value);
public function getError();
}
abstract class AbstractValidator implement Validator
{
protected $errors = array();
public function __construct()
{
// Do Something
}
public function getError()
{
return $this->errors;
}
}
class BooleanValidator extends AbstractValidator
{
public function __construct()
{
// Do Something
}
public validate($value)
{
$return = literalize($value);
if (!is_bool($value))
{
$this->errors[] = 'invalid_boolean';
return false;
}
return true;
}
}
PHP Programming