Skip to content

Commit 6d4965f

Browse files
committed
Fixed bug #78787
Not the first time inheritance of shadow properties causes an issue, thankfully this whole concept is gone in PHP 7.4.
1 parent 4c9ba3e commit 6d4965f

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
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.3.13
44

5+
- Core:
6+
. Fixed bug #78787 (Segfault with trait overriding inherited private shadow
7+
property). (Nikita)
8+
59
21 Nov 2019, PHP 7.3.12
610

711
- Core:

Zend/tests/bug78787.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #78787: Segfault with trait overriding inherited private shadow property
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
private $prop;
8+
}
9+
class C1 {
10+
/** Doc comment */
11+
private $prop;
12+
}
13+
class C2 extends C1 {
14+
}
15+
class C3 extends C2 {
16+
use T;
17+
}
18+
19+
?>
20+
===DONE===
21+
--EXPECT--
22+
===DONE===

Zend/zend_inheritance.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,14 @@ static void zend_do_traits_property_binding(zend_class_entry *ce) /* {{{ */
15951595
/* next: check for conflicts with current class */
15961596
if ((coliding_prop = zend_hash_find_ptr(&ce->properties_info, prop_name)) != NULL) {
15971597
if (coliding_prop->flags & ZEND_ACC_SHADOW) {
1598-
zend_string_release_ex(coliding_prop->name, 0);
1599-
if (coliding_prop->doc_comment) {
1600-
zend_string_release_ex(coliding_prop->doc_comment, 0);
1601-
}
1598+
/* Only free if shadow is coming from direct parent,
1599+
* otherwise these weren't copied in the first place. */
1600+
if (coliding_prop->ce == ce->parent) {
1601+
zend_string_release_ex(coliding_prop->name, 0);
1602+
if (coliding_prop->doc_comment) {
1603+
zend_string_release_ex(coliding_prop->doc_comment, 0);
1604+
}
1605+
}
16021606
zend_hash_del(&ce->properties_info, prop_name);
16031607
flags |= ZEND_ACC_CHANGED;
16041608
} else {

0 commit comments

Comments
 (0)