Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. /**
  2.  * @author you
  3.  */
  4. abstract class A
  5. {
  6.     abstract public function a (); //this is a contract
  7. }
  8. /**
  9.  * @author someone else
  10.  */
  11. abstract class B extends A
  12. {
  13.     abstract public function a ($t = false);
  14. }
  15. /**
  16.  * @author someone else
  17.  */
  18. class ConcreteA extends A
  19. {
  20.     public function a()
  21.     {
  22.         //do something
  23.     }
  24. }
  25.  
  26. /**
  27.  * @author someone else
  28.  */
  29. class ConcreteB extends B
  30. {
  31.     public function a($t = false)
  32.     {
  33.         //do something
  34.     }
  35. }
  36.  
  37. /**
  38.  * For handling A's
  39.  * @author you
  40.  */
  41. class AHandler
  42. {
  43.     public function doA(A $object)
  44.     {
  45.         $object->a();
  46.     }
  47. }
  48.  
  49.  
  50. //someone elses code...
  51. $obj1 = new ConcreteB();
  52. $obj2 = new ConcreteA();
  53.  
  54. //your code
  55. $handler = new AHandler();
  56. $handler->doA($obj2); //works fine
  57. $handler->doA($obj1); //typehint works fine, so probably something like "call to undefined method a"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement