zval *backref = zend_hash_next_index_insert(ser->ids, return_value);
if (SUCCESS == ce->unserialize(backref, ce, (BYTE *) s->val, s->len, NULL)) {
RETVAL_ZVAL(backref, 0, 0);
- } else if (!EG(exception)) {
- zend_throw_exception_ex(spl_ce_UnexpectedValueException, IERR_INTERNAL_ERROR,
- "Failed to unserialize class %s", ce->name->val);
+ } else {
+ zval_ptr_dtor(backref);
+ ZVAL_NULL(backref);
+ if (!EG(exception)) {
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, IERR_INTERNAL_ERROR,
+ "Failed to unserialize class %s", ce->name->val);
+ }
}
zend_string_release(s);
} else {
}
}
+class except implements Serializable {
+ function __construct (public $onserialize = false) {}
+ function serialize() : string {
+ if ($this->onserialize)
+ throw new Exception("except on serialize");
+ return "<<data>>";
+ }
+ function unserialize(string $data) : void {
+ throw new Exception("except on unserialize");
+ }
+}
+
echo "\n";
$t = new test;
$s = ion\serialize($tree);
echo $s,"\n";
debug_zval_dump(ion\unserialize($s));
+
+try {
+ ion\serialize(new except(true));
+} catch (Exception $e) {
+ printf("caught %s: %s\n", get_class($e), $e->getMessage());
+}
+try {
+ ion\unserialize(ion\serialize(new except()));
+} catch (Exception $e) {
+ printf("caught %s: %s\n", get_class($e), $e->getMessage());
+}
?>
DONE
--EXPECTF--
Deprecated: recursive implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %sserialize/serializable.php on line %d
+Deprecated: except implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %sserialize/serializable.php on line %d
+
[S::test::{{"foobar"}},r::1]
array(2) refcount(2){
[0]=>
NULL
}
}
+caught Exception: except on serialize
+caught Exception: except on unserialize
DONE