Guest User

Untitled

a guest
Jan 17th, 2018
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <?php
  2. /**
  3. * @created 09.01.2018
  4. * @author Smiley <smiley@chillerlan.net>
  5. * @copyright 2018 Smiley
  6. * @license MIT
  7. */
  8.  
  9. namespace Example;
  10.  
  11. interface A {
  12. public function log(string $message):A;
  13. public function doStuff():A;
  14. }
  15.  
  16. interface B {
  17. public function log(string $message):B;
  18. public function doOtherStuff():B;
  19. }
  20.  
  21. trait Log{
  22.  
  23. public function log(string $message){
  24. echo $message.PHP_EOL;
  25.  
  26. return $this;
  27. }
  28.  
  29. }
  30.  
  31. class ClassA implements A{
  32.  
  33. use Log{
  34. log as _log;
  35. }
  36.  
  37. public function log(string $message):A{
  38. return $this->_log($message);
  39. }
  40.  
  41. public function doStuff():A{
  42. return $this;
  43. }
  44.  
  45. }
  46.  
  47. // proposal
  48. class ClassB implements B{
  49.  
  50. use Log{
  51. log as log:B; // a new return type
  52. }
  53.  
  54. public function doOtherStuff():B{
  55. return $this;
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment