stringable_trait.phpt 648 B

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