summaryrefslogtreecommitdiffstats
path: root/lib/mysql.php
diff options
context:
space:
mode:
authorFernando da Silva Sousa <wild.nando@gmail.com>2020-10-23 18:20:42 -0300
committerFernando da Silva Sousa <wild.nando@gmail.com>2020-10-23 18:20:42 -0300
commit645b30664769c2ad4478a43d0849ffff9669c892 (patch)
tree6f83ba38982e6ae41245e22cc6e7b8ae828897f3 /lib/mysql.php
parentb1aed042d7cd27bd8705d5524ec0c0a930d546fd (diff)
downloadphp7-mysql-shim-645b30664769c2ad4478a43d0849ffff9669c892.zip
php7-mysql-shim-645b30664769c2ad4478a43d0849ffff9669c892.tar.gz
php7-mysql-shim-645b30664769c2ad4478a43d0849ffff9669c892.tar.bz2
Fix possibility of empty backtrace caused by traces without file and line
Diffstat (limited to 'lib/mysql.php')
-rw-r--r--lib/mysql.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index 6473868..1ebc5e5 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -737,10 +737,20 @@ namespace Dshafik {
$type = strtolower(gettype($result));
$file = "";
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
- if (isset($backtrace[1], $backtrace[1]['file'], $backtrace[1]['line'])) {
- $caller = $backtrace[1];
- $file = $caller['file'] . ':' . $caller['line'];
- }
+ $backtraceIndex = 0;
+
+ /**
+ * Iterate through backtrace until find an backtrace with origin
+ * Some methods may not leave file and line metadata like call_user_func_array and __call
+ */
+ do {
+ $currentBacktrace = $backtrace[$backtraceIndex];
+ $callerHasFileAndLine = isset($currentBacktrace['file'], $currentBacktrace['line']);
+
+ if ($callerHasFileAndLine && $currentBacktrace['file'] != __FILE__) {
+ $file = $currentBacktrace['file'] . ':' . $currentBacktrace['line'];
+ }
+ } while ($backtraceIndex++ < count($backtrace) && $file == "");
if ($function !== 'mysql_fetch_object') {
trigger_error(