fork(12) download
  1. <?php
  2.  
  3. class A
  4. {
  5. public function abc()
  6. {
  7. $a = '';
  8. $a .= self::test();
  9. $a .= static::test();
  10. return $a;
  11. }
  12.  
  13. public static function test()
  14. {
  15. return 'A';
  16. }
  17.  
  18. public function __toString()
  19. {
  20. return get_class($this) . "\n";
  21. }
  22.  
  23. public static function createSelfObject()
  24. {
  25. return new self();
  26. }
  27.  
  28. public static function createStaticObject()
  29. {
  30. return new static();
  31. }
  32. }
  33.  
  34. class B extends A
  35. {
  36. public function abc()
  37. {
  38. return parent::abc() . "\n";
  39. }
  40.  
  41. public static function test()
  42. {
  43. return 'B';
  44. }
  45. }
  46.  
  47. $a = new A();
  48. echo "Class A: ";
  49. echo $a->abc();
  50. echo "***\n";
  51.  
  52. $b = new B();
  53. echo "Class B: ";
  54. echo $b->abc();
  55. echo "***\n";
  56.  
  57. $a1 = A::createSelfObject();
  58. echo 'A::createSelfObject() -> ' . $a1;
  59. $a2 = A::createStaticObject();
  60. echo 'A::createStaticObject() -> ' . $a2;
  61. $b1 = B::createSelfObject();
  62. echo 'B::createSelfObject() -> ' . $b1;
  63. $b2 = B::createStaticObject();
  64. echo 'B::createStaticObject() -> ' . $b2;
  65.  
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Class A: AA***
Class B: AB
***
A::createSelfObject() -> A
A::createStaticObject() -> A
B::createSelfObject() -> A
B::createStaticObject() -> B