Enhanced Utils::printSafe() to output more information about arrays

This commit is contained in:
Vladimir Razuvaev 2017-07-14 15:16:43 +07:00
parent 3f04d29628
commit a3b40db0fb

View File

@ -253,6 +253,23 @@ class Utils
if (is_object($var)) { if (is_object($var)) {
return 'instance of ' . get_class($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) { if ('' === $var) {
return '(empty string)'; return '(empty string)';
} }