diff options
-rw-r--r-- | Zend/tests/traits/bug65576a.phpt | 31 | ||||
-rw-r--r-- | Zend/tests/traits/bug65576b.phpt | 33 | ||||
-rw-r--r-- | Zend/zend_inheritance.c | 4 |
3 files changed, 66 insertions, 2 deletions
diff --git a/Zend/tests/traits/bug65576a.phpt b/Zend/tests/traits/bug65576a.phpt new file mode 100644 index 0000000000..49b2ba0c96 --- /dev/null +++ b/Zend/tests/traits/bug65576a.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #65576 (Constructor from trait conflicts with inherited constructor) +--FILE-- +<?php + +trait T +{ + public function __construct() + { + echo "Trait contructor\n"; + } +} + +class A +{ + public function __construct() + { + echo "Parent constructor\n"; + } +} + +class B extends A +{ + use T; +} + +new B(); + +--EXPECT-- +Trait contructor + diff --git a/Zend/tests/traits/bug65576b.phpt b/Zend/tests/traits/bug65576b.phpt new file mode 100644 index 0000000000..3be52ba7c9 --- /dev/null +++ b/Zend/tests/traits/bug65576b.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #65576 (Constructor from trait conflicts with inherited constructor) +--FILE-- +<?php + +trait T +{ + public function __construct() + { + parent::__construct(); + echo "Trait contructor\n"; + } +} + +class A +{ + public function __construct() + { + echo "Parent constructor\n"; + } +} + +class B extends A +{ + use T; +} + +new B(); + +--EXPECT-- +Parent constructor +Trait contructor + diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 8f0d9fecb7..cf2a3cb4ad 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -992,7 +992,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zen if (!strncmp(mname->val, ZEND_CLONE_FUNC_NAME, mname->len)) { ce->clone = fe; fe->common.fn_flags |= ZEND_ACC_CLONE; } else if (!strncmp(mname->val, ZEND_CONSTRUCTOR_FUNC_NAME, mname->len)) { - if (ce->constructor) { + if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) { zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name->val); } ce->constructor = fe; fe->common.fn_flags |= ZEND_ACC_CTOR; @@ -1019,7 +1019,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zen zend_str_tolower_copy(lowercase_name->val, ce->name->val, ce->name->len); lowercase_name = zend_new_interned_string(lowercase_name TSRMLS_CC); if (!memcmp(mname->val, lowercase_name->val, mname->len)) { - if (ce->constructor) { + if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) { zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name->val); } ce->constructor = fe; |