Page MenuHomePhabricator

D9935.id23836.diff
No OneTemporary

D9935.id23836.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
@@ -590,6 +590,15 @@
')',
)),
phutil_var_export(array('foo', 'bar' => array('baz' => new stdClass()))));
+
+ $this->assertEqual(
+ implode("\n", array(
+ 'array(',
+ " 0 => '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
@@ -1080,12 +1080,48 @@
* @return string
*/
function phutil_var_export($var) {
- $regex = array(
- "/=>\s*\n\s+/" => '=> ',
- "/array\s*\(\n\s*\)/" => 'array()',
- '/array\s+\(/' => 'array(',
- );
- $var = var_export($var, true);
- return preg_replace(array_keys($regex), array_values($regex), $var);
+ if ($var === null) {
+ return 'null';
+ } else if ($var === true) {
+ return 'true';
+ } else if ($var === false) {
+ return 'false';
+ }
+
+ if (is_array($var)) {
+ if (count($var) === 0) {
+ return 'array()';
+ }
+
+ $output = array();
+ $output[] = 'array(';
+
+ static $indent = 0;
+
+ foreach ($var as $key => $value) {
+ $indent = $indent + 2;
+
+ $output[] = implode('', array(
+ str_repeat(' ', $indent),
+ phutil_var_export($key),
+ ' => ',
+ phutil_var_export($value),
+ ',',
+ ));
+
+ $indent = $indent - 2;
+ }
+
+ $output[] = str_repeat(' ', $indent).')';
+
+ return implode("\n", $output);
+ }
+
+ if (is_object($var)) {
+ $var = var_export($var, true);
+ return preg_replace("/array\(\n\)/", 'array()', $var);
+ }
+
+ return var_export($var, true);
}

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 6:49 AM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6740722
Default Alt Text
D9935.id23836.diff (1 KB)

Event Timeline