Skip to content

Commit 701460b

Browse files
committed
Fixed bug #76502
1 parent b20bcbc commit 701460b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.1.20
44

5+
- Core:
6+
. Fixed bug #76502 (Chain of mixed exceptions and errors does not serialize
7+
properly). (Nikita)
8+
59
- Date:
610
. Fixed bug #76462 (Undefined property: DateInterval::$f). (Anatol)
711

Zend/tests/bug76502.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #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+
13+
foreach ($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()) ----
26+
before: Exception.previous == Exception
27+
after : Exception.previous == Exception
28+
---- Error(Error()) ----
29+
before: Error.previous == Error
30+
after : Error.previous == Error
31+
---- Error(Exception()) ----
32+
before: Error.previous == Exception
33+
after : Error.previous == Exception
34+
---- Exception(Error()) ----
35+
before: Exception.previous == Error
36+
after : Exception.previous == Error

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ ZEND_METHOD(exception, __wakeup)
323323
CHECK_EXC_TYPE(ZEND_STR_TRACE, IS_ARRAY);
324324
pvalue = zend_read_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1, 1, &value);
325325
if (pvalue && Z_TYPE_P(pvalue) != IS_NULL && (Z_TYPE_P(pvalue) != IS_OBJECT ||
326-
!instanceof_function(Z_OBJCE_P(pvalue), i_get_exception_base(object)) ||
326+
!instanceof_function(Z_OBJCE_P(pvalue), zend_ce_throwable) ||
327327
pvalue == object)) {
328328
zend_unset_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1);
329329
}

0 commit comments

Comments
 (0)