Skip to content

Commit

Permalink
bug #29741 [VarExporter] fix exporting array indexes (xabbuh)
Browse files Browse the repository at this point in the history
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
-------

3c936f4 [VarExporter] fix exporting array indexes
  • Loading branch information
fabpot committed Jan 1, 2019
2 parents 4f31408 + 3c936f4 commit 113ba10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarExporter/Internal/Exporter.php
Expand Up @@ -232,7 +232,7 @@ public static function export($value, $indent = '')
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";
Expand Down
@@ -0,0 +1,8 @@
<?php

return [
5 => true,
1 => true,
2 => true,
true,
];
Expand Up @@ -112,6 +112,7 @@ public function provideExport()

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();
Expand Down

0 comments on commit 113ba10

Please sign in to comment.