Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15282452
D9936.id23837.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D9936.id23837.diff
View Options
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
@@ -573,9 +573,9 @@
$this->assertEqual(
implode("\n", array(
'array(',
- ' 0 => 1,',
- ' 1 => 2,',
- ' 2 => 3,',
+ ' 1,',
+ ' 2,',
+ ' 3,',
')',
)),
phutil_var_export(array(1, 2, 3)));
@@ -583,6 +583,15 @@
$this->assertEqual(
implode("\n", array(
'array(',
+ " 'foo' => 'bar',",
+ " 'bar' => 'baz',",
+ ')',
+ )),
+ phutil_var_export(array('foo' => 'bar', 'bar' => 'baz')));
+
+ $this->assertEqual(
+ implode("\n", array(
+ 'array(',
" 0 => 'foo',",
" 'bar' => array(",
" 'baz' => stdClass::__set_state(array()),",
@@ -594,7 +603,7 @@
$this->assertEqual(
implode("\n", array(
'array(',
- " 0 => 'array ()',",
+ " 'array ()',",
')',
)),
phutil_var_export(array('array ()')));
diff --git a/src/utils/utils.php b/src/utils/utils.php
--- a/src/utils/utils.php
+++ b/src/utils/utils.php
@@ -1094,6 +1094,9 @@
return 'array()';
}
+ // Don't show keys for non-associative arrays.
+ $show_keys = (array_keys($var) !== range(0, count($var) - 1));
+
$output = array();
$output[] = 'array(';
@@ -1104,8 +1107,7 @@
$output[] = implode('', array(
str_repeat(' ', $indent),
- phutil_var_export($key),
- ' => ',
+ $show_keys ? phutil_var_export($key).' => ' : '',
phutil_var_export($value),
',',
));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 12:13 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7223136
Default Alt Text
D9936.id23837.diff (1 KB)
Attached To
Mode
D9936: Don't export keys for non-associative arrays
Attached
Detach File
Event Timeline
Log In to Comment