lsb_001.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. --EXPECT--
  40. TestClassStatic
  41. TestClassConst
  42. TestClassFunction
  43. ChildClassStatic
  44. ChildClassConst
  45. ChildClassFunction
  46. TestClassStatic
  47. TestClassConst
  48. TestClassFunction