Skip to content

Commit 3f8c729

Browse files
committed
Traits refactoring
1 parent 3f0dcc0 commit 3f8c729

18 files changed

+341
-429
lines changed

Zend/tests/traits/bug60153.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class C implements IFoo {
1616
}
1717

1818
--EXPECTF--
19-
Fatal error: Declaration of C::oneArgument() must be compatible with IFoo::oneArgument($a) in %s on line %d
19+
Fatal error: Declaration of TFoo::oneArgument() must be compatible with IFoo::oneArgument($a) in %s on line %d

Zend/tests/traits/bug60217b.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ $o = new CBroken;
2323
$o->foo(1);
2424

2525
--EXPECTF--
26-
Fatal error: Declaration of TBroken1::foo($a) must be compatible with TBroken2::foo($a, $b = 0) in %s on line %d
26+
Fatal error: Declaration of TBroken2::foo($a, $b = 0) must be compatible with TBroken1::foo($a) in %s on line %d

Zend/tests/traits/bug60217c.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ $o = new CBroken;
2323
$o->foo(1);
2424

2525
--EXPECTF--
26-
Fatal error: Declaration of TBroken1::foo($a, $b = 0) must be compatible with TBroken2::foo($a) in %s on line %d
26+
Fatal error: Declaration of TBroken2::foo($a) must be compatible with TBroken1::foo($a, $b = 0) in %s on line %d

Zend/tests/traits/bugs/abstract-methods05.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ class TraitsTest1 {
2222

2323
?>
2424
--EXPECTF--
25-
Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d
25+
Fatal error: Declaration of THelloA::hello($a) must be compatible with THelloB::hello() in %s on line %d

Zend/tests/traits/bugs/abstract-methods06.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class TraitsTest1 {
2323

2424
?>
2525
--EXPECTF--
26-
Fatal error: Declaration of THelloA::hello($a) must be compatible with THelloB::hello() in %s on line %d
26+
Fatal error: Declaration of THelloB::hello() must be compatible with THelloA::hello($a) in %s on line %d

Zend/tests/traits/error_010.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ trait c {
1010
public function test() { return 2; }
1111
}
1212

13-
trait b {
14-
public function test() { return 1; }
15-
}
16-
1713
class bar {
18-
use foo, c { c::test insteadof foo, b; }
19-
use foo, c { c::test insteadof foo, b; }
14+
use foo, c { c::test insteadof foo; }
15+
use foo, c { c::test insteadof foo; }
2016
}
2117

2218
$x = new bar;

Zend/tests/traits/inheritance003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ $o->sayHello(array());
3535
--EXPECTF--
3636
World!
3737

38-
Fatal error: Declaration of MyHelloWorld::sayHello() must be compatible with Base::sayHello(array $a) in %s on line %d
38+
Fatal error: Declaration of SayWorld::sayHello(Base $d) must be compatible with Base::sayHello(array $a) in %s on line %d

Zend/tests/traits/language014.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Aliasing leading to conflict should result in error message
3+
--FILE--
4+
<?php
5+
error_reporting(E_ALL);
6+
7+
trait Hello {
8+
public function hello() {
9+
echo 'Hello';
10+
}
11+
}
12+
13+
trait World {
14+
public function world() {
15+
echo ' World!';
16+
}
17+
}
18+
19+
20+
class MyClass {
21+
use Hello, World { world as hello; }
22+
}
23+
24+
$o = new MyClass();
25+
$o->hello();
26+
$o->world();
27+
28+
?>
29+
--EXPECTF--
30+
Fatal error: Trait method hello has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d

Zend/tests/traits/language015.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Invalid conflict resolution (unused trait as lhs of "insteadof")
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
function foo() {echo "T1\n";}
7+
}
8+
trait T2 {
9+
function foo() {echo "T2\n";}
10+
}
11+
class C {
12+
use T1 {
13+
T2::foo insteadof T1;
14+
}
15+
}
16+
--EXPECTF--
17+
Fatal error: Trait T2 is not used in %s on line %d

Zend/tests/traits/language016.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Invalid conflict resolution (unused trait as rhs of "insteadof")
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
function foo() {echo "T1\n";}
7+
}
8+
trait T2 {
9+
function foo() {echo "T2\n";}
10+
}
11+
class C {
12+
use T1 {
13+
T1::foo insteadof T2;
14+
}
15+
}
16+
--EXPECTF--
17+
Fatal error: Trait T2 is not used in %s on line %d

Zend/tests/traits/language017.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Invalid conflict resolution (unused trait as lhs of "as")
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
function foo() {echo "T1\n";}
7+
}
8+
trait T2 {
9+
function foo() {echo "T2\n";}
10+
}
11+
class C {
12+
use T1 {
13+
T2::foo as private;
14+
}
15+
}
16+
--EXPECTF--
17+
Fatal error: Trait T2 is not used in %s on line %d

Zend/tests/traits/language018.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
abstract alias
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
function foo() {}
7+
}
8+
class C1 {
9+
use T1 {
10+
T1::foo as abstract;
11+
}
12+
}
13+
?>
14+
--EXPECTF--
15+
Fatal error: Cannot use 'abstarct' as method modifier in %s on line %d

Zend/tests/traits/language019.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
final alias
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
function foo() {}
7+
}
8+
class C1 {
9+
use T1 {
10+
T1::foo as final;
11+
}
12+
}
13+
?>
14+
--EXPECTF--
15+
Fatal error: Cannot use 'final' as method modifier in %s on line %d

Zend/zend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ struct _zend_trait_precedence {
437437

438438
zend_class_entry** exclude_from_classes;
439439

440-
union _zend_function* function;
440+
union _zend_function* function; /* FIXME: kept in 5.4 for BC, not used */
441441
};
442442
typedef struct _zend_trait_precedence zend_trait_precedence;
443443

@@ -455,7 +455,7 @@ struct _zend_trait_alias {
455455
*/
456456
zend_uint modifiers;
457457

458-
union _zend_function* function;
458+
union _zend_function* function; /* FIXME: kept in 5.4 for BC, not used */
459459
};
460460
typedef struct _zend_trait_alias zend_trait_alias;
461461

0 commit comments

Comments
 (0)