From 6f65d2d6ef99a2a5138f2e2e2e18052a5d8f24ca Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 16 May 2026 09:32:26 +0200 Subject: [PATCH] Make array_find available for PHP < 8.4 array_find is a useful function, but only available in PHP 8.4 or later. Here we implement it ourselves if it's not already defined, to make it available for all supported PHP versions. --- boot.php | 1 + include/php_compat.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 include/php_compat.php diff --git a/boot.php b/boot.php index 420637125..d6673d130 100644 --- a/boot.php +++ b/boot.php @@ -42,6 +42,7 @@ use Zotlabs\Web\HttpMeta; require_once('vendor/autoload.php'); +require_once('include/php_compat.php'); require_once('include/config.php'); require_once('include/network.php'); require_once('include/plugin.php'); diff --git a/include/php_compat.php b/include/php_compat.php new file mode 100644 index 000000000..de54aca50 --- /dev/null +++ b/include/php_compat.php @@ -0,0 +1,28 @@ + + * + * SPDX-License-Identifier: MIT + * + * This file contains functions that allow us to use convenient functions from + * later PHP versions in earlier versions where these functions may not be + * supported directly. + */ + +if (!function_exists('array_find')) { + + // array_find is defined in PHP 8.4 or higher, so for earlier PHP versions we + // define it here. + function array_find(array $array, callable $callback): mixed { + foreach ($array as $key => $entry) { + if ($callback($entry, $key) === true) { + return $entry; + } + } + + return null; + } +}