bug #29741 [VarExporter] fix exporting array indexes (xabbuh)

This PR was merged into the 4.2 branch.

Discussion
----------

[VarExporter] fix exporting array indexes

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29715
| License       | MIT
| Doc PR        |

Commits
-------

3c936f447b [VarExporter] fix exporting array indexes
This commit is contained in:
Fabien Potencier 2019-01-01 18:38:21 +01:00
commit 113ba10f8f
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();