I would like to use the function array_key_first (PHP 7 >= 7.3.0).
My current PHP Version is 7.2
I use the "Polyfill" as described within the "User Contributed Notes" section of corresponding PHP manual
If I call the array_key_first function in my index.php which is where the polyfill is, everything works fine.
If I call the array_key_first function within a PHP self-written class, it doesn't work.
How can I define "Polyfills" so that they are "globally" available?
I don't want to define a class method an call it with $this->array_key_first...
I include the following code in my index.php file
if (!function_exists('array_key_first')) {
function array_key_first(array $array){
if (count($array)) {
reset($array);
return key($array);
}
return null;
}
}
Thanks for hints