lsb_002.phpt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. --EXPECT--
  43. TestClassStatic
  44. TestClassConst
  45. TestClassFunction
  46. ChildClassStatic
  47. ChildClassConst
  48. ChildClassFunction
  49. TestClassStatic
  50. TestClassConst
  51. TestClassFunction