constant_arrays.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --TEST--
  2. Constant arrays
  3. --INI--
  4. zend.enable_gc=1
  5. --FILE--
  6. <?php
  7. define('FOOBAR', [1, 2, 3, ['foo' => 'bar']]);
  8. const FOO_BAR = [1, 2, 3, ['foo' => 'bar']];
  9. $x = FOOBAR;
  10. $x[0] = 7;
  11. var_dump($x, FOOBAR);
  12. $x = FOO_BAR;
  13. $x[0] = 7;
  14. var_dump($x, FOO_BAR);
  15. // ensure references are removed
  16. $x = 7;
  17. $y = [&$x];
  18. define('QUX', $y);
  19. $y[0] = 3;
  20. var_dump($x, $y, QUX);
  21. // ensure objects not allowed in arrays
  22. var_dump(define('ELEPHPANT', [new StdClass]));
  23. // ensure recursion doesn't crash
  24. $recursive = [];
  25. $recursive[0] = &$recursive;
  26. var_dump(define('RECURSION', $recursive));
  27. --EXPECTF--
  28. array(4) {
  29. [0]=>
  30. int(7)
  31. [1]=>
  32. int(2)
  33. [2]=>
  34. int(3)
  35. [3]=>
  36. array(1) {
  37. ["foo"]=>
  38. string(3) "bar"
  39. }
  40. }
  41. array(4) {
  42. [0]=>
  43. int(1)
  44. [1]=>
  45. int(2)
  46. [2]=>
  47. int(3)
  48. [3]=>
  49. array(1) {
  50. ["foo"]=>
  51. string(3) "bar"
  52. }
  53. }
  54. array(4) {
  55. [0]=>
  56. int(7)
  57. [1]=>
  58. int(2)
  59. [2]=>
  60. int(3)
  61. [3]=>
  62. array(1) {
  63. ["foo"]=>
  64. string(3) "bar"
  65. }
  66. }
  67. array(4) {
  68. [0]=>
  69. int(1)
  70. [1]=>
  71. int(2)
  72. [2]=>
  73. int(3)
  74. [3]=>
  75. array(1) {
  76. ["foo"]=>
  77. string(3) "bar"
  78. }
  79. }
  80. int(3)
  81. array(1) {
  82. [0]=>
  83. &int(3)
  84. }
  85. array(1) {
  86. [0]=>
  87. int(7)
  88. }
  89. Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
  90. bool(false)
  91. Warning: Constants cannot be recursive arrays in %s on line %d
  92. bool(false)