]> granicus.if.org Git - php/commitdiff
Fix use of type copy ctor when importing trait properties
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 3 Nov 2020 14:29:18 +0000 (15:29 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 3 Nov 2020 14:29:18 +0000 (15:29 +0100)
We shouldn't call the copy constructor inside the original type,
duh.

Zend/zend_inheritance.c
ext/opcache/tests/preload_ind.inc [new file with mode: 0644]
ext/opcache/tests/preload_ind.phpt [new file with mode: 0644]
ext/opcache/tests/preload_ind2.inc [new file with mode: 0644]

index c3aad9f614c289c69ac1215e4b51626e9ee3e2dd..b0f4055be1bfe43f893369fc83e60d4d11368a16 100644 (file)
@@ -2049,8 +2049,9 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
                        Z_TRY_ADDREF_P(prop_value);
                        doc_comment = property_info->doc_comment ? zend_string_copy(property_info->doc_comment) : NULL;
 
-                       zend_type_copy_ctor(&property_info->type, /* persistent */ 0);
-                       new_prop = zend_declare_typed_property(ce, prop_name, prop_value, flags, doc_comment, property_info->type);
+                       zend_type type = property_info->type;
+                       zend_type_copy_ctor(&type, /* persistent */ 0);
+                       new_prop = zend_declare_typed_property(ce, prop_name, prop_value, flags, doc_comment, type);
 
                        if (property_info->attributes) {
                                new_prop->attributes = property_info->attributes;
diff --git a/ext/opcache/tests/preload_ind.inc b/ext/opcache/tests/preload_ind.inc
new file mode 100644 (file)
index 0000000..f7f3f4f
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+opcache_compile_file(__DIR__ . '/preload_ind2.inc');
diff --git a/ext/opcache/tests/preload_ind.phpt b/ext/opcache/tests/preload_ind.phpt
new file mode 100644 (file)
index 0000000..158fc15
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Various tests that need an opcache_compile_file() indirected preload file
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_ind.inc
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
+?>
+--FILE--
+OK
+--EXPECTF--
+Warning: Can't preload class C with unresolved property types in %s on line %d
+OK
diff --git a/ext/opcache/tests/preload_ind2.inc b/ext/opcache/tests/preload_ind2.inc
new file mode 100644 (file)
index 0000000..93a741f
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+trait T {
+    public X|Y $prop;
+}
+
+class C {
+    use T;
+}