Skip to content

Instantly share code, notes, and snippets.

@tobiastom
Created October 13, 2009 20:25
Show Gist options
  • Save tobiastom/209527 to your computer and use it in GitHub Desktop.
Save tobiastom/209527 to your computer and use it in GitHub Desktop.
<?php
class error {
public $title;
public $code;
public $contains = array();
public function __construct($title, $code = 0, Array $contains = array()) {
$this->title = $title;
$this->code = $code;
$this->contains = $contains;
}
}
class object {
public $foo;
public $baz;
public function validate(Error &$error = null) {
$errors = array();
if (!$this->foo) {
$errors[] = new error('Foo not set');
}
if (!$this->baz) {
$errors[] = new error('blah');
}
if (empty($errors)) {
return true;
}
$error = count($errors) == 1 ? $errors[0] : new error('multiple errors', 0, $errors);
return false;
}
public function loadModule($module) {
throw new exception('module not found: ' . $module);
}
}
$object = new object;
$error = null;
var_dump($object->validate($error));
var_dump($error);
$object->foo = 'baz';
$object->baz = 'bam';
$error = null;
var_dump($object->validate($error));
var_dump($error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment