Skip to content

Commit 162687d

Browse files
committed
fix: Support PHP 8.4
1 parent 686cdad commit 162687d

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

services/reports.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@
3131
include_once __DIR__ . '/../classes/ReportUtil.php';
3232

3333
/**
34-
* Search the array for an item an returns the first one found.
34+
* Search the array for an item and returns the first one found.
35+
* (Built-in to PHP 8.4; defined here for earlier PHP versions.)
3536
* @param $array
3637
* @param $filter
3738
* @return mixed
3839
*/
39-
function array_find($filter, $array)
40+
if (!function_exists('array_find')) { function array_find($array, $filter)
4041
{
41-
foreach ($array as $item) {
42-
if ($filter($item)) {
43-
return $item;
42+
foreach ($array as $key => $val) {
43+
if ($filter($val, $key)) {
44+
return $val;
4445
}
4546
}
4647
return null;
47-
}
48+
}}
4849

4950
$manager->registerService('report', [
5051
"caption" => "All Pages",
@@ -172,9 +173,9 @@ function array_find($filter, $array)
172173
if (!isset($mapA[$value])) {
173174
$mapA[$value] = [];
174175
}
175-
if (array_find(function ($a) use (&$page) {
176+
if (array_find($mapA[$value], function ($a,$disregarded_key) use (&$page) {
176177
return $a->title() === $page->title();
177-
}, $mapA[$value]) === null) {
178+
}) === null) {
178179
$mapA[$value][] = $page;
179180
}
180181
}
@@ -188,9 +189,9 @@ function array_find($filter, $array)
188189
if (!isset($mapImg[$value])) {
189190
$mapImg[$value] = [];
190191
}
191-
if (array_find(function ($a) use ($page) {
192+
if (array_find($mapImg[$value], function ($a,$disregarded_key) use ($page) {
192193
return $a->title() === $page->title();
193-
}, $mapImg[$value]) === null) {
194+
}) === null) {
194195
$mapImg[$value][] = $page;
195196
}
196197
}

0 commit comments

Comments
 (0)