bug68553.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --TEST--
  2. Bug #68553 (array_column: null values in $index_key become incrementing keys in result)
  3. --FILE--
  4. <?php
  5. $i = 100;
  6. /* increase the resource id to make test stable */
  7. while ($i--) {
  8. $fd = fopen(__FILE__, "r");
  9. fclose($fd);
  10. }
  11. $a = [
  12. ['a' => 10],
  13. ['a' => 20],
  14. ['a' => true],
  15. ['a' => false],
  16. ['a' => fopen(__FILE__, "r")],
  17. ['a' => -5],
  18. ['a' => 7.38],
  19. ['a' => null, "test"],
  20. ['a' => null],
  21. ];
  22. var_dump(array_column($a, null, 'a'));
  23. try {
  24. var_dump(array_column([['a' => new stdClass]], null, 'a'));
  25. } catch (Error $e) {
  26. echo $e->getMessage(), "\n";
  27. }
  28. try {
  29. var_dump(array_column([['a' => []]], null, 'a'));
  30. } catch (Error $e) {
  31. echo $e->getMessage(), "\n";
  32. }
  33. ?>
  34. --EXPECTF--
  35. Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
  36. Deprecated: Implicit conversion from float 7.38 to int loses precision in %s on line %d
  37. array(8) {
  38. [10]=>
  39. array(1) {
  40. ["a"]=>
  41. int(10)
  42. }
  43. [20]=>
  44. array(1) {
  45. ["a"]=>
  46. int(20)
  47. }
  48. [1]=>
  49. array(1) {
  50. ["a"]=>
  51. bool(true)
  52. }
  53. [0]=>
  54. array(1) {
  55. ["a"]=>
  56. bool(false)
  57. }
  58. [%d]=>
  59. array(1) {
  60. ["a"]=>
  61. resource(%d) of type (stream)
  62. }
  63. [-5]=>
  64. array(1) {
  65. ["a"]=>
  66. int(-5)
  67. }
  68. [7]=>
  69. array(1) {
  70. ["a"]=>
  71. float(7.38)
  72. }
  73. [""]=>
  74. array(1) {
  75. ["a"]=>
  76. NULL
  77. }
  78. }
  79. Illegal offset type
  80. Illegal offset type