From 0d4c69cc6fc81a989c6ee3df50a3aa80f48a1ebc Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 21 Mar 2022 18:47:42 -0300 Subject: [PATCH] Add check to avoid error in PHP 8 and return some information about the unexpected value Signed-off-by: RD WebDesign --- advanced/index.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index d0c5fc5d..95afcdff 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -170,7 +170,15 @@ function queryAds($serverName) { $serverName ); $queryAds = file($queryAdsURL, FILE_IGNORE_NEW_LINES); - $queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAds))); + + // $queryAds must be an array (to avoid PHP 8.0+ error) + if (is_array($queryAds)) { + $queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAds))); + } else { + // if not an array, return an error message + return array("0" => "error", "1" => "Not an array:
(".gettype($queryAds).")
".print_r($queryAds, true)); + } + $queryTime = sprintf("%.0f", (microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]) - $preQueryTime); // Exception Handling