com php-src: Fix use of type copy ctor when importing trait properties: Zend/zend_inheritance.c ext/opcache/tests/preload_ind .inc
ext/opcache/tests/preload_ind.phpt ext/opcache/t ests/preload_ind2.inc
| From: | Nikita Popov | Date: | Tue, 03 Nov 2020 14:29:18 +0000 |
| Subject: | com php-src: Fix use of type copy ctor when importing trait properties: Zend/zend_inheritance.c ext/opcache/tests/preload_ind .inc ext/opcache/tests/preload_ind.phpt ext/opcache/t ests/preload_ind2.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114050@lists.php.net to get a copy of this message | ||
Commit: 9fd8e00f1a90acd5e23bfcb6f8b0217187bcfb1d
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 3 Nov 2020 15:29:18 +0100
Parents: 7e5531755812a46841fc24ade5f71aefde69cf96
Branches: PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9fd8e00f1a90acd5e23bfcb6f8b0217187bcfb1d
Log:
Fix use of type copy ctor when importing trait properties
We shouldn't call the copy constructor inside the original type,
duh.
Changed paths:
M Zend/zend_inheritance.c
A ext/opcache/tests/preload_ind.inc
A ext/opcache/tests/preload_ind.phpt
A ext/opcache/tests/preload_ind2.inc
Diff:
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index c3aad9f614c..b0f4055be1b 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -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
index 00000000000..f7f3f4f231c
--- /dev/null
+++ b/ext/opcache/tests/preload_ind.inc
@@ -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
index 00000000000..158fc15ab6b
--- /dev/null
+++ b/ext/opcache/tests/preload_ind.phpt
@@ -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
index 00000000000..93a741f95a9
--- /dev/null
+++ b/ext/opcache/tests/preload_ind2.inc
@@ -0,0 +1,9 @@
+<?php
+
+trait T {
+ public X|Y $prop;
+}
+
+class C {
+ use T;
+}