<?php
trait X{
function test(A $a){}
function tryA(A $a){
$this->test($a);
}
}
trait Y{
function test(B $b){}
function tryB(B $b){
$this->test($b);
}
}
class Test{
use X, Y{
X::test insteadof Y;
}
}
class A{}
class B{}
$x = new Test;
$x->tryA(new A);
$x->tryB(new B);
Fatal error: Uncaught TypeError: Test::test(): Argument #1 ($a) must be of type A, B given, called in /in/R8ZKl on line 15 and defined in /in/R8ZKl:4
Stack trace:
#0 /in/R8ZKl(15): Test->test(Object(B))
#1 /in/R8ZKl(30): Test->tryB(Object(B))
#2 {main}
thrown in /in/R8ZKl on line 4
Process exited with code 255.
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/R8ZKl on line 20
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Test::test(), 0 passed in /in/R8ZKl on line 28 and exactly 1 expected in /in/R8ZKl:4
Stack trace:
#0 /in/R8ZKl(28): Test->test()
#1 {main}
thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Test::test(), 0 passed in /in/R8ZKl on line 28 and exactly 1 expected in /in/R8ZKl:4
Stack trace:
#0 /in/R8ZKl(28): Test->test()
#1 {main}
thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/R8ZKl on line 20
Fatal error: Uncaught TypeError: Argument 1 passed to Test::test() must be an instance of A, none given, called in /in/R8ZKl on line 28 and defined in /in/R8ZKl:4
Stack trace:
#0 /in/R8ZKl(28): Test->test()
#1 {main}
thrown in /in/R8ZKl on line 4
Process exited with code 255.
Catchable fatal error: Argument 1 passed to Test::test() must be an instance of A, none given, called in /in/R8ZKl on line 28 and defined in /in/R8ZKl on line 4
Process exited with code 255.