lsb_001.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. ZE2 Late Static Binding in a static 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 static function testStaticVar() {
  12. return static::$staticVar;
  13. }
  14. public static function testClassConst() {
  15. return static::CLASS_CONST;
  16. }
  17. public static 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. echo TestClass::testStaticVar() . "\n";
  30. echo TestClass::testClassConst() . "\n";
  31. echo TestClass::testStaticFunction() . "\n";
  32. echo ChildClass1::testStaticVar() . "\n";
  33. echo ChildClass1::testClassConst() . "\n";
  34. echo ChildClass1::testStaticFunction() . "\n";
  35. echo ChildClass2::testStaticVar() . "\n";
  36. echo ChildClass2::testClassConst() . "\n";
  37. echo ChildClass2::testStaticFunction() . "\n";
  38. ?>
  39. ==DONE==
  40. --EXPECT--
  41. TestClassStatic
  42. TestClassConst
  43. TestClassFunction
  44. ChildClassStatic
  45. ChildClassConst
  46. ChildClassFunction
  47. TestClassStatic
  48. TestClassConst
  49. TestClassFunction
  50. ==DONE==