Closed
Description
symfony/var-dumper version affected: "^5.1"
Description
It seems dd()
has issue with the representation of the keys of nested arrays in some special cases, in function of array size and structure. I observe incorrect keys when I dump example zip codes in a nested array with a size greater than 2500 elements while a flat dump seems correct. See the output of the following code, in particular the items after the "09669" key.
First i observed this using dd()
in Laravel, now tested directly the symfony/var-dumper
component.
How to reproduce
<?php
// First run: composer require --dev symfony/var-dumper
// Then execute this file in terminal with different size and type values.
require_once __DIR__ . '/vendor/autoload.php';
$size = 2501; // 2500
$type = 'nested'; // flat
$zipCodes = explode("\n", file_get_contents('https://gist.githubusercontent.com/marcell-ferenc/73e39563058f31c01ccf467c62d34aa4/raw/fe99c6003eac9dca8f450c3817ace465c5d222b7/example_zip_codes.csv'));
$data = [];
foreach (array_slice($zipCodes, 0, $size) as $zipCode) {
if ($type == 'flat') {
$data[(string) $zipCode] = $zipCode;
} else {
$data['test'][(string) $zipCode] = $zipCode;
}
}
dd($data);
Additional context
unexpected results, nested array with 2501 items:
array:1 [▼
"test" => array:2501 [▼
"01069" => "01069"
"01067" => "01067"
"01097" => "01097"
...
"09648" => "09648"
"09661" => "09661"
"09669" => "09669"
0 => "10115"
1 => "10117"
2 => "10119"
...
]
expected results, flat array with 2501 items:
array:2501 [▼
"01069" => "01069"
"01067" => "01067"
"01097" => "01097"
...
"09648" => "09648"
"09661" => "09661"
"09669" => "09669"
10115 => "10115"
10117 => "10117"
10119 => "10119"
...
]
expected results, nested array with 2500 items:
array:1 [▼
"test" => array:2500 [▼
"01069" => "01069"
"01067" => "01067"
"01097" => "01097"
...
"09648" => "09648"
"09661" => "09661"
"09669" => "09669"
10115 => "10115"
10117 => "10117"
10119 => "10119"
...
]