Page MenuHomePhabricator

D9936.diff
No OneTemporary

D9936.diff

diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php
--- a/src/utils/__tests__/PhutilUtilsTestCase.php
+++ b/src/utils/__tests__/PhutilUtilsTestCase.php
@@ -580,9 +580,9 @@
$this->assertEqual(
implode("\n", array(
'array(',
- ' 0 => 1,',
- ' 1 => 2,',
- ' 2 => 3,',
+ ' 1,',
+ ' 2,',
+ ' 3,',
')',
)),
phutil_var_export(array(1, 2, 3)));
diff --git a/src/utils/utils.php b/src/utils/utils.php
--- a/src/utils/utils.php
+++ b/src/utils/utils.php
@@ -1100,13 +1100,18 @@
return 'array()';
}
+ // Don't show keys for non-associative arrays.
+ $show_keys = (array_keys($var) !== range(0, count($var) - 1));
+
$output = array();
$output[] = 'array(';
foreach ($var as $key => $value) {
// Adjust the indentation of the value.
$value = str_replace("\n", "\n ", phutil_var_export($value));
- $output[] = ' '.var_export($key, true).' => '.$value.',';
+ $output[] = ' '.
+ ($show_keys ? var_export($key, true).' => ' : '').
+ $value.',';
}
$output[] = ')';

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 4, 5:42 AM (20 h, 32 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6669312
Default Alt Text
D9936.diff (1 KB)

Event Timeline