semi_reserved_006.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Test semi-reserved method and constant names and trait conflict resolution
  3. --FILE--
  4. <?php
  5. trait TraitA
  6. {
  7. public function catch(){ echo __METHOD__, PHP_EOL; }
  8. private function list(){ echo __METHOD__, PHP_EOL; }
  9. }
  10. trait TraitB
  11. {
  12. static $list = ['a' => ['b' => ['c']]];
  13. public static function catch(){ echo __METHOD__, PHP_EOL; }
  14. private static function throw(){ echo __METHOD__, PHP_EOL; }
  15. private static function self(){ echo __METHOD__, PHP_EOL; }
  16. }
  17. trait TraitC
  18. {
  19. public static function exit(){ echo __METHOD__, PHP_EOL; }
  20. protected static function try(){ echo __METHOD__, PHP_EOL; }
  21. }
  22. class Foo
  23. {
  24. use TraitA, TraitB {
  25. TraitA
  26. ::
  27. catch insteadof namespace\TraitB;
  28. TraitA::list as public foreach;
  29. TraitB::throw as public;
  30. TraitB::self as public;
  31. }
  32. use TraitC {
  33. try as public attempt;
  34. exit as die;
  35. \TraitC::exit as bye;
  36. namespace\TraitC::exit as byebye;
  37. TraitC
  38. ::
  39. exit as farewell;
  40. }
  41. }
  42. (new Foo)->catch();
  43. (new Foo)->foreach();
  44. Foo::throw();
  45. Foo::self();
  46. var_dump(Foo::$list['a']);
  47. Foo::attempt();
  48. Foo::die();
  49. Foo::bye();
  50. Foo::byebye();
  51. Foo::farewell();
  52. echo "\nDone\n";
  53. ?>
  54. --EXPECT--
  55. TraitA::catch
  56. TraitA::list
  57. TraitB::throw
  58. TraitB::self
  59. array(1) {
  60. ["b"]=>
  61. array(1) {
  62. [0]=>
  63. string(1) "c"
  64. }
  65. }
  66. TraitC::try
  67. TraitC::exit
  68. TraitC::exit
  69. TraitC::exit
  70. TraitC::exit
  71. Done