Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Zend/tests/traits/bug65576a.phpt
Original file line number Diff line number Diff line change
@@ -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

33 changes: 33 additions & 0 deletions Zend/tests/traits/bug65576b.phpt
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3650,7 +3650,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, const char* mname, uint
if (!strncmp(mname, ZEND_CLONE_FUNC_NAME, mname_len)) {
ce->clone = fe; fe->common.fn_flags |= ZEND_ACC_CLONE;
} else if (!strncmp(mname, ZEND_CONSTRUCTOR_FUNC_NAME, mname_len)) {
if (ce->constructor) {
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
zend_error(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name);
}
ce->constructor = fe; fe->common.fn_flags |= ZEND_ACC_CTOR;
Expand All @@ -3675,7 +3675,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, const char* mname, uint
zend_str_tolower_copy(lowercase_name, ce->name, ce->name_length);
lowercase_name = (char*)zend_new_interned_string(lowercase_name, ce->name_length + 1, 1 TSRMLS_CC);
if (!memcmp(mname, lowercase_name, mname_len)) {
if (ce->constructor) {
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
zend_error(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name);
}
ce->constructor = fe;
Expand Down