Skip to content

Commit 9fd8e00

Browse files
committed
Fix use of type copy ctor when importing trait properties
We shouldn't call the copy constructor inside the original type, duh.
1 parent 7e55317 commit 9fd8e00

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

Zend/zend_inheritance.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,9 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
20492049
Z_TRY_ADDREF_P(prop_value);
20502050
doc_comment = property_info->doc_comment ? zend_string_copy(property_info->doc_comment) : NULL;
20512051

2052-
zend_type_copy_ctor(&property_info->type, /* persistent */ 0);
2053-
new_prop = zend_declare_typed_property(ce, prop_name, prop_value, flags, doc_comment, property_info->type);
2052+
zend_type type = property_info->type;
2053+
zend_type_copy_ctor(&type, /* persistent */ 0);
2054+
new_prop = zend_declare_typed_property(ce, prop_name, prop_value, flags, doc_comment, type);
20542055

20552056
if (property_info->attributes) {
20562057
new_prop->attributes = property_info->attributes;

ext/opcache/tests/preload_ind.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
opcache_compile_file(__DIR__ . '/preload_ind2.inc');

ext/opcache/tests/preload_ind.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Various tests that need an opcache_compile_file() indirected preload file
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_ind.inc
8+
--SKIPIF--
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
OK
15+
--EXPECTF--
16+
Warning: Can't preload class C with unresolved property types in %s on line %d
17+
OK

ext/opcache/tests/preload_ind2.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
trait T {
4+
public X|Y $prop;
5+
}
6+
7+
class C {
8+
use T;
9+
}

0 commit comments

Comments
 (0)