3v4l.org

run code in 300+ PHP versions simultaneously
<?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(); }

preferences:
27.57 ms | 407 KiB | 5 Q