constants_basic_004.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. --TEST--
  2. Test properties with array default values using class constants as keys and values.
  3. --FILE--
  4. <?php
  5. class X
  6. {
  7. // Static and instance array using class constants
  8. public static $sa_x = array(B::KEY => B::VALUE);
  9. public $a_x = array(B::KEY => B::VALUE);
  10. }
  11. class B
  12. {
  13. const KEY = "key";
  14. const VALUE = "value";
  15. // Static and instance array using class constants with self
  16. public static $sa_b = array(self::KEY => self::VALUE);
  17. public $a_b = array(self::KEY => self::VALUE);
  18. }
  19. class C extends B
  20. {
  21. // Static and instance array using class constants with parent
  22. public static $sa_c_parent = array(parent::KEY => parent::VALUE);
  23. public $a_c_parent = array(parent::KEY => parent::VALUE);
  24. // Static and instance array using class constants with self (constants should be inherited)
  25. public static $sa_c_self = array(self::KEY => self::VALUE);
  26. public $a_c_self = array(self::KEY => self::VALUE);
  27. // Should also include inherited properties from B.
  28. }
  29. echo "\nStatic properties:\n";
  30. var_dump(X::$sa_x, B::$sa_b, C::$sa_b, C::$sa_c_parent, C::$sa_c_self);
  31. echo "\nInstance properties:\n";
  32. $x = new x;
  33. $b = new B;
  34. $c = new C;
  35. var_dump($x, $b, $c);
  36. ?>
  37. --EXPECTF--
  38. Static properties:
  39. array(1) {
  40. ["key"]=>
  41. string(5) "value"
  42. }
  43. array(1) {
  44. ["key"]=>
  45. string(5) "value"
  46. }
  47. array(1) {
  48. ["key"]=>
  49. string(5) "value"
  50. }
  51. array(1) {
  52. ["key"]=>
  53. string(5) "value"
  54. }
  55. array(1) {
  56. ["key"]=>
  57. string(5) "value"
  58. }
  59. Instance properties:
  60. object(X)#%d (1) {
  61. ["a_x"]=>
  62. array(1) {
  63. ["key"]=>
  64. string(5) "value"
  65. }
  66. }
  67. object(B)#%d (1) {
  68. ["a_b"]=>
  69. array(1) {
  70. ["key"]=>
  71. string(5) "value"
  72. }
  73. }
  74. object(C)#%d (3) {
  75. ["a_b"]=>
  76. array(1) {
  77. ["key"]=>
  78. string(5) "value"
  79. }
  80. ["a_c_parent"]=>
  81. array(1) {
  82. ["key"]=>
  83. string(5) "value"
  84. }
  85. ["a_c_self"]=>
  86. array(1) {
  87. ["key"]=>
  88. string(5) "value"
  89. }
  90. }