phpopcache

ini_get_all('Zend OPcache') echos warning that the extension couldn't be found


I have an app where the user or rather the admin, can check the configuration of PHP. Cause it is an API the ini values are collected by calling ini_get_all with all the extension names.

This is the code I use

public function getLoadedExtensions(): array
{
    $extensions = [];
    $loadedExtensions = get_loaded_extensions();

    foreach ($loadedExtensions as $extensionName) {
        try {
            $iniValues = @ini_get_all($extensionName);
        } catch (Throwable) {
            $iniValues = [];
        }

        $extension = new PhpExtension();
        $extension->setExtensionName($extensionName);
        $extension->setVersion(phpversion($extensionName));

        $extensions[] = $extension;
    }

    return $extensions;
}

It works for nearly all extensions as expected, just for Zend OPcache and a few with no ini values I get the following warning:

<b>Warning</b>:  ini_get_all(): Extension &quot;Zend OPcache&quot; cannot be found in <b>/var/www/html/src/Maintenance/PhpInfo/PhpInfoService.php</b> on line <b>39</b><br />

Is there a clean way to get the ini values used by OPcache? I currently run a ini_get_all() and filter if the key starts with opcache.


Solution

  • I found a way to get the correct values. This piece of code gets the correct infos:

    $extension = new ReflectionExtension('Zend OPcache'); // or the name of any other extension
    $iniValues = $extension->getINIEntries();
    

    This way all extensions get the correct ini values.