Created
October 13, 2009 20:25
-
-
Save tobiastom/209527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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