Skip to content

Commit a68c5eb

Browse files
committed
Add inheritance test and fix some related issues
1 parent 075e272 commit a68c5eb

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Various inheritance scenarios for properties/methods with union types
3+
--FILE--
4+
<?php
5+
6+
class X {
7+
public A|B|int $prop;
8+
public function method(A|B|int $arg): A|B|int { }
9+
10+
private A|B|int $prop2;
11+
private function method2(A|B|int $arg): A|B|int { }
12+
}
13+
14+
class Y extends X {
15+
}
16+
17+
trait T {
18+
public A|B|int $prop;
19+
public function method(A|B|int $arg): A|B|int { }
20+
21+
private A|B|int $prop2;
22+
private function method2(A|B|int $arg): A|B|int { }
23+
}
24+
25+
class Z {
26+
use T;
27+
}
28+
29+
class U extends X {
30+
use T;
31+
}
32+
33+
class V extends X {
34+
use T;
35+
36+
public A|B|int $prop;
37+
public function method(A|B|int $arg): A|B|int { }
38+
39+
private A|B|int $prop2;
40+
private function method2(A|B|int $arg): A|B|int { }
41+
}
42+
43+
?>
44+
===DONE===
45+
--EXPECT--
46+
===DONE===

Zend/zend_inheritance.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ static void overridden_ptr_dtor(zval *zv) /* {{{ */
4343
static void zend_type_copy_ctor(zend_type *type) {
4444
if (ZEND_TYPE_HAS_LIST(*type)) {
4545
zend_type_list *old_list = ZEND_TYPE_LIST(*type);
46-
zend_type_list *new_list = emalloc(ZEND_TYPE_LIST_SIZE(old_list->num_types));
46+
size_t size = ZEND_TYPE_LIST_SIZE(old_list->num_types);
47+
zend_type_list *new_list = ZEND_TYPE_USES_ARENA(*type)
48+
? zend_arena_alloc(&CG(arena), size) : emalloc(size);
4749
memcpy(new_list, old_list, ZEND_TYPE_LIST_SIZE(old_list->num_types));
4850
ZEND_TYPE_SET_PTR(*type, new_list);
4951

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,21 @@ static void zend_hash_clone_prop_info(HashTable *ht)
235235

236236
if (ZEND_TYPE_HAS_LIST(prop_info->type)) {
237237
zend_type_list *list = ZEND_TYPE_LIST(prop_info->type);
238-
ZEND_ASSERT(IN_ARENA(list));
239-
list = ARENA_REALLOC(list);
240-
ZEND_TYPE_SET_PTR(prop_info->type, list);
241-
242-
void **entry;
243-
ZEND_TYPE_LIST_FOREACH_PTR(ZEND_TYPE_LIST(prop_info->type), entry) {
244-
if (ZEND_TYPE_LIST_IS_CE(*entry)) {
245-
zend_class_entry *ce = ZEND_TYPE_LIST_GET_CE(*entry);
246-
if (IN_ARENA(ce)) {
247-
ce = ARENA_REALLOC(ce);
248-
*entry = ZEND_TYPE_LIST_ENCODE_CE(ce);
238+
if (IN_ARENA(list)) {
239+
list = ARENA_REALLOC(list);
240+
ZEND_TYPE_SET_PTR(prop_info->type, list);
241+
242+
void **entry;
243+
ZEND_TYPE_LIST_FOREACH_PTR(ZEND_TYPE_LIST(prop_info->type), entry) {
244+
if (ZEND_TYPE_LIST_IS_CE(*entry)) {
245+
zend_class_entry *ce = ZEND_TYPE_LIST_GET_CE(*entry);
246+
if (IN_ARENA(ce)) {
247+
ce = ARENA_REALLOC(ce);
248+
*entry = ZEND_TYPE_LIST_ENCODE_CE(ce);
249+
}
249250
}
250-
}
251-
} ZEND_TYPE_LIST_FOREACH_END();
251+
} ZEND_TYPE_LIST_FOREACH_END();
252+
}
252253
} else if (ZEND_TYPE_HAS_CE(prop_info->type)) {
253254
zend_class_entry *ce = ZEND_TYPE_CE(prop_info->type);
254255
if (IN_ARENA(ce)) {

0 commit comments

Comments
 (0)