static_properties_002.phpt 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Reflection and inheriting static properties
  3. --FILE--
  4. <?php
  5. class base {
  6. static protected $prop = 2;
  7. static function show() {
  8. echo __METHOD__ . '(' . self::$prop . ")\n";
  9. }
  10. static function inc() {
  11. base::$prop++;
  12. echo __METHOD__ . "()\n";
  13. }
  14. }
  15. class derived extends base {
  16. static public $prop = 2;
  17. static function show() {
  18. echo __METHOD__ . '(' . self::$prop . ")\n";
  19. }
  20. static function inc() {
  21. derived::$prop++;
  22. echo __METHOD__ . "()\n";
  23. }
  24. }
  25. base::show();
  26. derived::show();
  27. base::inc();
  28. base::show();
  29. derived::show();
  30. derived::inc();
  31. base::show();
  32. derived::show();
  33. $r = new ReflectionClass('derived');
  34. echo 'Number of properties: '. count($r->getStaticProperties()) . "\n";
  35. echo "Done\n";
  36. ?>
  37. --EXPECT--
  38. base::show(2)
  39. derived::show(2)
  40. base::inc()
  41. base::show(3)
  42. derived::show(2)
  43. derived::inc()
  44. base::show(3)
  45. derived::show(3)
  46. Number of properties: 1
  47. Done