lsb_002.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. ZE2 Late Static Binding in an instance function
  3. --FILE--
  4. <?php
  5. class TestClass {
  6. protected static $staticVar = 'TestClassStatic';
  7. const CLASS_CONST = 'TestClassConst';
  8. protected static function staticFunction() {
  9. return 'TestClassFunction';
  10. }
  11. public function testStaticVar() {
  12. return static::$staticVar;
  13. }
  14. public function testClassConst() {
  15. return static::CLASS_CONST;
  16. }
  17. public function testStaticFunction() {
  18. return static::staticFunction();
  19. }
  20. }
  21. class ChildClass1 extends TestClass {
  22. protected static $staticVar = 'ChildClassStatic';
  23. const CLASS_CONST = 'ChildClassConst';
  24. protected static function staticFunction() {
  25. return 'ChildClassFunction';
  26. }
  27. }
  28. class ChildClass2 extends TestClass {}
  29. $testClass = new TestClass();
  30. $childClass1 = new ChildClass1();
  31. $childClass2 = new ChildClass2();
  32. echo $testClass->testStaticVar() . "\n";
  33. echo $testClass->testClassConst() . "\n";
  34. echo $testClass->testStaticFunction() . "\n";
  35. echo $childClass1->testStaticVar() . "\n";
  36. echo $childClass1->testClassConst() . "\n";
  37. echo $childClass1->testStaticFunction() . "\n";
  38. echo $childClass2->testStaticVar() . "\n";
  39. echo $childClass2->testClassConst() . "\n";
  40. echo $childClass2->testStaticFunction() . "\n";
  41. ?>
  42. ==DONE==
  43. --EXPECT--
  44. TestClassStatic
  45. TestClassConst
  46. TestClassFunction
  47. ChildClassStatic
  48. ChildClassConst
  49. ChildClassFunction
  50. TestClassStatic
  51. TestClassConst
  52. TestClassFunction
  53. ==DONE==