Guest User

Untitled

a guest
Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. namespace Alpha
  3. {
  4. class Foo
  5. {
  6. public function test() {}
  7. }
  8. }
  9.  
  10. namespace Beta
  11. {
  12. use Alpha as NamespaceAlias;
  13. use Alpha\Foo as ClassAlias;
  14.  
  15. class TestClass
  16. {
  17. public function methodA()
  18. {
  19. return new \Alpha\Foo();
  20. }
  21.  
  22. public function methodB()
  23. {
  24. return new ClassAlias;
  25. }
  26.  
  27. public function methodC()
  28. {
  29. return new NamespaceAlias\Foo();
  30. }
  31. }
  32.  
  33. $testClass = new TestClass();
  34. $testClass->methodA()->test(); // OK
  35. $testClass->methodB()->test(); // OK
  36. $testClass->methodC()->test(); // OK
  37. }
  38.  
  39. namespace Gamma
  40. {
  41. class Child extends \Beta\TestClass {}
  42.  
  43. $child = new Child();
  44. $child->methodA()->test(); // OK
  45. $child->methodB()->test(); // fails
  46. $child->methodC()->test(); // fails
  47. }
Add Comment
Please, Sign In to add comment