<?php
class Serializable_Exception extends Exception
{
protected $serialized_backtrace;
public function __sleep()
{
// If we just serialize, we lose the backtrace info completely
// But we may well want to log or inspect this string later...
if ( is_null($this->serialized_backtrace) ) {
$this->serialized_backtrace = $this->getTraceAsString();
}
return array_keys(get_object_vars($this));
}
public function enhancedGetTraceAsString()
{
if ( isset($this->serialized_backtrace) ) {
return $this->serialized_backtrace;
}
else {
return parent::getTraceAsString();
}
}
}
function foo($x) {
throw new Serializable_Exception;
}
try {
foo( new SimpleXMLElement('<test />') );
}
catch ( Exception $e ) {
echo $e->enhancedGetTraceAsString();
echo "\n -- \n";
echo unserialize( serialize($e) )->enhancedGetTraceAsString();
}
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IHPI5 on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IHPI5 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/IHPI5 on line 5
Process exited with code 255.