Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
102
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.  
  3. class ParentClass
  4. {
  5. const SOME_VAL = 80;
  6.  
  7. public function getMyVal()
  8. {
  9. printf('I am %s, my $someval is %d%s',static::class, static::SOME_VAL, PHP_EOL);
  10. }
  11. }
  12.  
  13. class ChildClass1 extends ParentClass
  14. {
  15. public function doIt()
  16. {
  17. $this->getMyVal();
  18. }
  19. }
  20.  
  21. class ChildClass2 extends ParentClass
  22. {
  23. const SOME_VAL = 35;
  24.  
  25. public function doIt()
  26. {
  27. $this->getMyVal();
  28. }
  29. }
  30.  
  31. $c1 = new ChildClass1();
  32. $c1->doIt();
  33.  
  34. $c2 = new ChildClass2();
  35. $c2->doIt();
  36.  
  37. $c1 = new ChildClass1();
  38. $c1->doIt();
  39.  
  40. /**
  41. I am ChildClass1, my $someval is 80
  42. I am ChildClass2, my $someval is 35
  43. I am ChildClass1, my $someval is 80
  44. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement