From a3b40db0fbc316d012810a78256bdf9925dce6f9 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Fri, 14 Jul 2017 15:16:43 +0700 Subject: [PATCH] Enhanced Utils::printSafe() to output more information about arrays --- src/Utils/Utils.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index db9da6e..cb6242b 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -253,6 +253,23 @@ class Utils if (is_object($var)) { return 'instance of ' . get_class($var); } + if (is_array($var)) { + $count = count($var); + if (!isset($var[0]) && $count > 0) { + $keys = []; + $keyCount = 0; + foreach ($var as $key => $value) { + $keys[] = $key; + if ($keyCount++ > 4) { + break; + } + } + $msg = "associative array($count) with first keys: " . implode(', ', $keys); + } else { + $msg = "array($count)"; + } + return $msg; + } if ('' === $var) { return '(empty string)'; }