Skip to content

Commit

Permalink
Fix use of type copy ctor when importing trait properties
Browse files Browse the repository at this point in the history
We shouldn't call the copy constructor inside the original type,
duh.
  • Loading branch information
nikic committed Nov 3, 2020
1 parent 7e55317 commit 9fd8e00
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/tests/preload_ind.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
opcache_compile_file(__DIR__ . '/preload_ind2.inc');
17 changes: 17 additions & 0 deletions ext/opcache/tests/preload_ind.phpt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions ext/opcache/tests/preload_ind2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

trait T {
public X|Y $prop;
}

class C {
use T;
}

0 comments on commit 9fd8e00

Please sign in to comment.