Code
$a = new Exception("foo");
try {
throw $a; //Line 1
} catch (Exception $e) {
throw $a; //Line 10;
}
<?php
class DumbException extends Exception {
/**
* Cleanup anything we need before serialisation
*
* @return string[] An array of member varible names to serialize
* @see http://php.planetmirror.com/manual/en/language.oop5.magic.php
*/
public function __sleep() {
return array('string','code');
}
/**
* Compare against another DumbException for equality.
*
* Since two exceptions can be !== because the trace / line / file
* information is different, we need to do this.
*/
public function cmp(DumbException $e) {
return (serialize($e) == serialize($this));
}
}
print '<pre>';
$a = new DumbException();
$b = new DumbException();
try {
try {
throw $b;
} catch (Exception $e) {
throw $a;
}
} catch (Exception $e) {
var_dump($a === $b);
var_dump($a == $b);
var_dump($b === $e);
var_dump($b == $e);
var_dump($a === $e);
var_dump($a == $e);
var_dump($b->cmp($e));
var_dump($a->cmp($e));
}
print '</pre>';
?>
