summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavey Shafik <me@daveyshafik.com>2020-10-25 17:30:14 -0700
committerGitHub <noreply@github.com>2020-10-25 17:30:14 -0700
commit033ec6b1e3c07276ad801396e39c1a783fd9105b (patch)
treefe1e960b3ff08394151b268618a2aab4c9d0c0c0 /lib
parent697e0eb466aa474ff054d7e6908ab873d77dcdcf (diff)
parent709444274c9e87383c3728ee347607e4ae6c7906 (diff)
downloadphp7-mysql-shim-033ec6b1e3c07276ad801396e39c1a783fd9105b.zip
php7-mysql-shim-033ec6b1e3c07276ad801396e39c1a783fd9105b.tar.gz
php7-mysql-shim-033ec6b1e3c07276ad801396e39c1a783fd9105b.tar.bz2
Merge pull request #54 from SWsistemas/master
Adds backtrace for illegal argument supplied warning
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
);
}