Skip to content

Commit

Permalink
RusticiSoftware#111: Resolve PHP 8.0 error when calling set_error_han…
Browse files Browse the repository at this point in the history
…dler
  • Loading branch information
Graham Berry committed Apr 10, 2024
1 parent 19acfc8 commit 73ce5aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/RemoteLRS.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function sendRequest($method, $resource) {
// normal handling
//
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
function ($errno, $errstr, $errfile, $errline) {
// "!== false" is intentional. strpos() can return 0, which is falsey, but returning
// 0 matches our "true" condition. Using strict equality to avoid that confusion.
if ($errno == E_NOTICE && strpos($errstr, 'Array to string conversion') !== false) {
Expand All @@ -162,7 +162,13 @@ function ($errno, $errstr, $errfile, $errline, array $errcontext) {
$fp = fopen($url, 'rb', false, $context);

if (! $fp) {
$content = "Request failed: $php_errormsg";
$content = "Request failed";

$last_error = error_get_last();

if($last_error && $last_error['type'] === E_ERROR) {
$content .= ": " . $last_error['message'];
}
}
}
catch (\ErrorException $ex) {
Expand Down

0 comments on commit 73ce5aa

Please sign in to comment.