Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions pinc/CharSuites.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ class CharSuite
}

// If we don't recognize the property, raise a notice and return null
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
"Undefined property via __get(): $name " . get_backtrace_loc(),
E_USER_NOTICE
);
return null;
Expand All @@ -105,11 +102,8 @@ class CharSuite
$this->_pickerset->name = $this->name;
} else {
// If we don't recognize the property, raise a notice
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
"Undefined property via __set(): $name " . get_backtrace_loc(),
E_USER_NOTICE
);
}
Expand Down
9 changes: 3 additions & 6 deletions pinc/DPDatabase.inc
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ final class DPDatabase
{
// Log the SQL error to the PHP error log and return a generic error
// for display to the user
$backtrace = debug_backtrace();
$caller = $backtrace[$backtrace_level]['file'] . ":" . $backtrace[$backtrace_level]['line'];
$from_caller = get_backtrace_loc($backtrace_level + 1);
$error = str_replace("\n", "\\n", mysqli_error(DPDatabase::get_connection()));
error_log("DPDatabase.inc - log_error from $caller: $error");
error_log("DPDatabase.inc - log_error $from_caller: $error");
return _("An error occurred during a database query and has been logged.");
}

Expand Down Expand Up @@ -196,13 +195,11 @@ final class DPDatabase
}

try {
$backtrace = debug_backtrace();
$caller = $backtrace[1]['file'] . ":" . $backtrace[1]['line'];

$message = sprintf(
"%s %s %s\n",
date("c"),
$caller,
get_backtrace_loc(depth: 2),
preg_replace("/\s+/", " ", $sql)
);
$fp = fopen(DPDatabase::$tracing_log, 'a');
Expand Down
5 changes: 1 addition & 4 deletions pinc/Project.inc
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,8 @@ class Project
}

// If we don't recognize the property, raise a notice and return null
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
"Undefined property via __get(): $name " . get_backtrace_loc(),
E_USER_NOTICE
);
return null;
Expand Down
20 changes: 20 additions & 0 deletions pinc/misc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,26 @@ function validate_csrf_token(): void
}
}

/**
* @param int $depth
* How deep in the call stack to get the location. 0 is the caller
* of `get_backtrace_loc`, 1 is the caller of that function, etc
Comment thread
cpeel marked this conversation as resolved.
* @return string
* Returns a trace location like "in foo.php on line 742"
* Omits the file name or linenumber clauses if they can't be found
*/
function get_backtrace_loc(int $depth = 1): string
{
$trace = debug_backtrace();
$loc = [];
if (($file = $trace[$depth]["file"] ?? "")) {
$loc[] = "in $file";
}
if (($line = $trace[$depth]["line"] ?? "")) {
$loc[] = "on line $line";
}
return join(" ", $loc);
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Expand Down