xref: /PHP-8.3/Zend/tests/stringable_trait.phpt (revision d478ae73)
1--TEST--
2Bug #81582: Stringable not implicitly declared if __toString() came from a trait
3--FILE--
4<?php
5
6trait T {
7    public function __toString(): string {
8        return "ok";
9    }
10}
11trait T2 {
12    use T;
13}
14
15class C {
16    use T;
17}
18class C2 {
19    use T2;
20}
21
22var_dump(new C instanceof Stringable);
23var_dump(new C2 instanceof Stringable);
24
25// The traits themselves should not implement Stringable -- traits cannot implement interfaces.
26$rc = new ReflectionClass(T::class);
27var_dump($rc->getInterfaceNames());
28$rc = new ReflectionClass(T2::class);
29var_dump($rc->getInterfaceNames());
30
31?>
32--EXPECT--
33bool(true)
34bool(true)
35array(0) {
36}
37array(0) {
38}
39