public function VarDumpService::varDump in Development Environment 8
Dumps the details of a variable.
Parameters
mixed $var: The variable for which details should be dumped.
bool $return: Whether or not to return the data to the calling function. If FALSE, the data is dumped to the screen.
bool $html: Whether or not the outputted data should be an HTML output, or plaintext.
int $level: The depth of $var that should be dumped. Set to 0 (zero) for full depth.
Return value
array|null An array containing the dumped data if $return is set to TRUE, or NULL otherwise.
Overrides VarDumpServiceInterface::varDump
File
- src/
Service/ VarDumpService.php, line 13
Class
- VarDumpService
- The VarDumpService class.
Namespace
Drupal\development_environment\ServiceCode
public function varDump($var, $return = FALSE, $html = FALSE, $level = 0) {
$spaces = "";
$space = $html ? " " : " ";
$newline = $html ? "<br />" : "\n";
for ($i = 1; $i <= 4; $i++) {
$spaces .= $space;
}
$tabs = $spaces;
for ($i = 1; $i <= $level; $i++) {
$tabs .= $spaces;
}
if (is_array($var)) {
$title = "Array";
}
elseif (is_object($var)) {
$title = get_class($var) . " Object";
}
$output = $title . $newline . $newline;
foreach ($var as $key => $value) {
if (is_array($value) || is_object($value)) {
$level++;
$value = $this
->varDump($value, TRUE, $html, $level);
$level--;
}
$output .= $tabs . "[" . $key . "] => " . $value . $newline;
}
if ($return) {
return $output;
}
else {
echo $output;
}
}