[VarExporter] fix exporting array indexes

This commit is contained in:
Christian Flothmann 2019-01-01 14:11:42 +01:00
parent 85b313d532
commit 3c936f447b
3 changed files with 10 additions and 1 deletions

View File

@ -232,7 +232,7 @@ class Exporter
if (!\is_int($k) || 1 !== $k - $j) {
$code .= self::export($k, $subIndent).' => ';
}
if (\is_int($k)) {
if (\is_int($k) && $k > $j) {
$j = $k;
}
$code .= self::export($v, $subIndent).",\n";

View File

@ -0,0 +1,8 @@
<?php
return [
5 => true,
1 => true,
2 => true,
true,
];

View File

@ -112,6 +112,7 @@ class VarExporterTest extends TestCase
yield array('bool', true, true);
yield array('simple-array', array(123, array('abc')), true);
yield array('partially-indexed-array', array(5 => true, 1 => true, 2 => true, 6 => true), true);
yield array('datetime', \DateTime::createFromFormat('U', 0));
$value = new \ArrayObject();