xref: /PHP-8.1/Zend/tests/bug76502.phpt (revision 701460ba)
1--TEST--
2Bug #76502: Chain of mixed exceptions and errors does not serialize properly
3--FILE--
4<?php
5
6$examples = [
7    "Exception(Exception())" => new Exception("outer", 0,  new Exception("inner")),
8    "Error(Error())"         => new Error("outer", 0, new Error("inner")),
9    "Error(Exception())"     => new Error("outer", 0, new Exception("inner")),
10    "Exception(Error())"     => new Exception("outer", 0, new Error("inner"))
11];
12
13foreach ($examples as $name => $example) {
14    $processed = unserialize(serialize($example));
15    $processedPrev = $processed->getPrevious();
16    echo "---- $name ----\n";
17    echo "before: ", get_class($example), ".previous == ",
18        get_class($example->getPrevious()), "\n";
19    echo "after : ", get_class($processed), ".previous == ",
20        $processedPrev ? get_class($processedPrev) : "null", "\n";
21}
22
23?>
24--EXPECT--
25---- Exception(Exception()) ----
26before: Exception.previous == Exception
27after : Exception.previous == Exception
28---- Error(Error()) ----
29before: Error.previous == Error
30after : Error.previous == Error
31---- Error(Exception()) ----
32before: Error.previous == Exception
33after : Error.previous == Exception
34---- Exception(Error()) ----
35before: Exception.previous == Error
36after : Exception.previous == Error
37