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