diff --git a/src/Symfony/Component/VarExporter/Internal/Exporter.php b/src/Symfony/Component/VarExporter/Internal/Exporter.php index bbb409e194..38a8e25088 100644 --- a/src/Symfony/Component/VarExporter/Internal/Exporter.php +++ b/src/Symfony/Component/VarExporter/Internal/Exporter.php @@ -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"; diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/partially-indexed-array.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/partially-indexed-array.php new file mode 100644 index 0000000000..647aa7e80f --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/partially-indexed-array.php @@ -0,0 +1,8 @@ + true, + 1 => true, + 2 => true, + true, +]; diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index 2d6c32a52e..c34a7e4fb7 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -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();