xref: /PHP-8.0/Zend/tests/trait_type_errors.phpt (revision fbe30592)
1--TEST--
2Type errors for methods from traits should refer to using class
3--FILE--
4<?php
5
6trait T {
7    public function test1($arg): int {
8        return $arg;
9    }
10    public function test2(int $arg) {
11    }
12    public function test3(int $arg = 42) {
13    }
14}
15
16class C {
17    use T;
18}
19class P extends C {
20}
21
22$c = new C;
23try {
24    $c->test1("foo");
25} catch (TypeError $e) {
26    echo $e->getMessage(), "\n";
27}
28try {
29    $c->test2("foo");
30} catch (TypeError $e) {
31    echo $e->getMessage(), "\n";
32}
33try {
34    $c->test3("foo");
35} catch (TypeError $e) {
36    echo $e->getMessage(), "\n";
37}
38
39?>
40--EXPECTF--
41C::test1(): Return value must be of type int, string returned
42C::test2(): Argument #1 ($arg) must be of type int, string given, called in %s on line %d
43C::test3(): Argument #1 ($arg) must be of type int, string given, called in %s on line %d
44