Skip to content

Commit 73429b3

Browse files
committed
Fixed inconsistent debug parameters and empty '(line )'
1 parent 926ac32 commit 73429b3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/Cake/basics.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,47 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
7676
if (Configure::read('debug') > 0) {
7777
$file = '';
7878
$line = '';
79+
$lineInfo = '';
7980
if ($showFrom) {
8081
$calledFrom = debug_backtrace();
8182
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
8283
$line = $calledFrom[0]['line'];
8384
}
8485
$html = <<<HTML
8586
<div class="cake-debug-output">
86-
<span><strong>%s</strong> (line <strong>%s</strong>)</span>
87+
%s
8788
<pre class="cake-debug">
8889
%s
8990
</pre>
9091
</div>
9192
HTML;
92-
$text = <<<TEXT
93+
$text = <<<TEXT
9394
94-
%s (line %s)
95+
%s
9596
########## DEBUG ##########
9697
%s
9798
###########################
9899
99100
TEXT;
100101
$template = $html;
101-
if (php_sapi_name() == 'cli') {
102+
if (php_sapi_name() == 'cli' || $showHtml === false) {
102103
$template = $text;
104+
if ($showFrom) {
105+
$lineInfo = sprintf('%s (line %s)', $file, $line);
106+
}
103107
}
104108
if ($showHtml === null && $template !== $text) {
105109
$showHtml = true;
106110
}
107111
$var = print_r($var, true);
108112
if ($showHtml) {
113+
$template = $html;
109114
$var = h($var);
115+
if ($showFrom) {
116+
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
117+
}
110118
}
111-
printf($template, $file, $line, $var);
119+
printf($template, $lineInfo, $var);
112120
}
113121
}
114122

0 commit comments

Comments
 (0)