Skip to content

Commit 3c936f4

Browse files
committed
[VarExporter] fix exporting array indexes
1 parent 85b313d commit 3c936f4

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/Symfony/Component/VarExporter/Internal/Exporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static function export($value, $indent = '')
232232
if (!\is_int($k) || 1 !== $k - $j) {
233233
$code .= self::export($k, $subIndent).' => ';
234234
}
235-
if (\is_int($k)) {
235+
if (\is_int($k) && $k > $j) {
236236
$j = $k;
237237
}
238238
$code .= self::export($v, $subIndent).",\n";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
5 => true,
5+
1 => true,
6+
2 => true,
7+
true,
8+
];

src/Symfony/Component/VarExporter/Tests/VarExporterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function provideExport()
112112

113113
yield array('bool', true, true);
114114
yield array('simple-array', array(123, array('abc')), true);
115+
yield array('partially-indexed-array', array(5 => true, 1 => true, 2 => true, 6 => true), true);
115116
yield array('datetime', \DateTime::createFromFormat('U', 0));
116117

117118
$value = new \ArrayObject();

0 commit comments

Comments
 (0)