Skip to content

Commit d5dd29c

Browse files
author
Julien Pauli
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Updated NEWS Fixed Bug #65576 (Constructor from trait conflicts with inherited constructor) Conflicts: Zend/zend_compile.c
2 parents d1a2c15 + d6eb3b4 commit d5dd29c

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

Zend/tests/traits/bug65576a.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #65576 (Constructor from trait conflicts with inherited constructor)
3+
--FILE--
4+
<?php
5+
6+
trait T
7+
{
8+
public function __construct()
9+
{
10+
echo "Trait contructor\n";
11+
}
12+
}
13+
14+
class A
15+
{
16+
public function __construct()
17+
{
18+
echo "Parent constructor\n";
19+
}
20+
}
21+
22+
class B extends A
23+
{
24+
use T;
25+
}
26+
27+
new B();
28+
29+
--EXPECT--
30+
Trait contructor
31+

Zend/tests/traits/bug65576b.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #65576 (Constructor from trait conflicts with inherited constructor)
3+
--FILE--
4+
<?php
5+
6+
trait T
7+
{
8+
public function __construct()
9+
{
10+
parent::__construct();
11+
echo "Trait contructor\n";
12+
}
13+
}
14+
15+
class A
16+
{
17+
public function __construct()
18+
{
19+
echo "Parent constructor\n";
20+
}
21+
}
22+
23+
class B extends A
24+
{
25+
use T;
26+
}
27+
28+
new B();
29+
30+
--EXPECT--
31+
Parent constructor
32+
Trait contructor
33+

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, const char* mname, uint
39793979
if (!strncmp(mname, ZEND_CLONE_FUNC_NAME, mname_len)) {
39803980
ce->clone = fe; fe->common.fn_flags |= ZEND_ACC_CLONE;
39813981
} else if (!strncmp(mname, ZEND_CONSTRUCTOR_FUNC_NAME, mname_len)) {
3982-
if (ce->constructor) {
3982+
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
39833983
zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name);
39843984
}
39853985
ce->constructor = fe; fe->common.fn_flags |= ZEND_ACC_CTOR;
@@ -4006,7 +4006,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, const char* mname, uint
40064006
zend_str_tolower_copy(lowercase_name, ce->name, ce->name_length);
40074007
lowercase_name = (char*)zend_new_interned_string(lowercase_name, ce->name_length + 1, 1 TSRMLS_CC);
40084008
if (!memcmp(mname, lowercase_name, mname_len)) {
4009-
if (ce->constructor) {
4009+
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
40104010
zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ce->name);
40114011
}
40124012
ce->constructor = fe;

0 commit comments

Comments
 (0)