summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mysql.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index a0ebb5a..d05d7a8 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -734,16 +734,34 @@ namespace Dshafik {
public static function checkValidResult($result, $function)
{
if (!($result instanceof \mysqli_result)) {
+ $type = strtolower(gettype($result));
+ $file = "";
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ $backtraceIndex = 0;
+
+ /**
+ * Iterate through backtrace until finding a backtrace with an 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(
- $function . '() expects parameter 1 to be resource, ' . strtolower(gettype($result)) . ' given',
+ "$function() expects parameter 1 to be resource, $type given on $file",
E_USER_WARNING
);
}
if ($function === 'mysql_fetch_object') {
trigger_error(
- $function . '(): supplied argument is not a valid MySQL result resource',
+ "$function(): supplied argument is not a valid MySQL result resource on $file",
E_USER_WARNING
);
}