1--TEST--
2Bug #72663 (1): Don't call __destruct if __wakeup not called or fails
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class Test1 {
8    public function __wakeup() {
9        echo "Wakeup\n";
10    }
11    public function __destruct() {
12        echo "Dtor\n";
13    }
14}
15
16#[AllowDynamicProperties]
17class Test2 {
18    public function __wakeup() {
19        throw new Exception('Unserialization forbidden');
20    }
21    public function __destruct() {
22        echo "Dtor\n";
23    }
24}
25
26// Unserialize object with error in properties
27$s = 'O:5:"Test1":1:{s:10:"";}';
28var_dump(unserialize($s));
29
30// Variation: Object is turned into a reference
31$s = 'O:5:"Test1":2:{i:0;R:1;s:10:"";}';
32var_dump(unserialize($s));
33
34// Unserialize object with throwing __wakeup
35$s = 'O:5:"Test2":0:{}';
36try {
37    var_dump(unserialize($s));
38} catch (Exception $e) {
39    echo "Caught\n";
40}
41//
42// Variation: Object is turned into a reference
43$s = 'O:5:"Test2":1:{i:0;R:1;}';
44try {
45    var_dump(unserialize($s));
46} catch (Exception $e) {
47    echo "Caught\n";
48}
49
50?>
51--EXPECTF--
52Warning: unserialize(): Error at offset 17 of 24 bytes in %s on line %d
53bool(false)
54
55Warning: unserialize(): Error at offset 25 of 32 bytes in %s on line %d
56bool(false)
57Caught
58Caught
59