Skip to content

Commit a664200

Browse files
committed
Fix file not found and eval()'d code in file path
1 parent a4108d8 commit a664200

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

DumpBacktrace.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,52 @@ function steevanb_dev_showCodePreview(id)
189189
*/
190190
protected static function getBacktraceDump(array $backtrace, $index, $previewPrefix)
191191
{
192+
$filePath = null;
193+
$line = null;
194+
$previewId = $previewPrefix . '_' . $index;
195+
192196
if (isset($backtrace['file'])) {
193-
$file = basename($backtrace['file']);
194-
$filePath = $backtrace['file'];
195-
$fileFound = true;
196-
} else {
197-
$filePath = null;
198-
$fileFound = false;
199-
}
197+
if (file_exists($backtrace['file'])) {
198+
$filePath = $backtrace['file'];
199+
$fileFound = true;
200200

201-
if (isset($backtrace['line'])) {
202-
$line = $backtrace['line'];
203-
$lineFound = true;
201+
if (isset($backtrace['line'])) {
202+
$line = $backtrace['line'];
203+
$lineFound = true;
204+
} else {
205+
$lineFound = false;
206+
}
207+
} elseif (substr($backtrace['file'], -16) === ' : eval()\'d code') {
208+
$fileAndLine = substr($backtrace['file'], 0, -16);
209+
$filePath = substr($fileAndLine, 0, strrpos($fileAndLine, '('));
210+
if (file_exists($filePath)) {
211+
$line = substr($fileAndLine, strrpos($fileAndLine, '(') + 1, -1);
212+
$fileFound = true;
213+
$lineFound = true;
214+
} else {
215+
$fileFound = false;
216+
$lineFound = false;
217+
}
218+
} else {
219+
$fileFound = false;
220+
$lineFound = false;
221+
}
204222
} else {
223+
$fileFound = false;
205224
$lineFound = false;
206225
}
207226

208227
if ($fileFound === false && $lineFound === false) {
209228
$fileLineHtml = '\Closure';
229+
$codePreview = null;
210230
} else {
211-
$previewId = $previewPrefix . '_' . $index;
212231
$codePreview = static::getCodePreview($filePath, $line);
213232
$fileLineHtml = '
214233
<a
215234
title="' . static::getFilePath($filePath) . '"
216235
onclick="steevanb_dev_showCodePreview(\'' . $previewId . '\')"
217236
>
218-
' . $file . '::' . $line . '
237+
' . basename($filePath) . '::' . $line . '
219238
</a>
220239
';
221240
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[![version](https://img.shields.io/badge/version-1.1.0-green.svg)](https://github.com/steevanb/php-backtrace/tree/1.1.0)
1+
[![version](https://img.shields.io/badge/version-1.1.1-green.svg)](https://github.com/steevanb/php-backtrace/tree/1.1.1)
22
[![php](https://img.shields.io/badge/php->=5.4-blue.svg)](http://php.net)
3-
![Lines](https://img.shields.io/badge/code lines-680-green.svg)
3+
![Lines](https://img.shields.io/badge/code lines-711-green.svg)
44
![Total Downloads](https://poser.pugx.org/steevanb/php-backtrace/downloads)
5-
[![SensionLabsInsight](https://img.shields.io/badge/SensionLabsInsight-platinum-brightgreen.svg)](https://insight.sensiolabs.com/projects/2b6dd6a0-ef48-4b5b-ba13-e825e0841be3/analyses/5)
5+
[![SensionLabsInsight](https://img.shields.io/badge/SensionLabsInsight-platinum-brightgreen.svg)](https://insight.sensiolabs.com/projects/2b6dd6a0-ef48-4b5b-ba13-e825e0841be3/analyses/7)
66
[![Scrutinizer](https://scrutinizer-ci.com/g/steevanb/php-backtrace/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/steevanb/php-backtrace/)
77

88
php-backtrace

backtrace.png

-49.1 KB
Loading

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
1.1.1 (2016-10-12)
2+
------------------
3+
4+
- Fix file not found errors
5+
- Fix eval()'d code in file path
6+
- Update backtrace.png
7+
8+
1.1.0 (2016-10-10)
9+
------------------
10+
11+
- Add eDump() and getDump()
12+
113
1.0.1 (2016-08-16)
214
------------------
315

0 commit comments

Comments
 (0)