The extension_loaded Function

The extension_loaded function checks whether the specified extension is loaded in the current PHP configuration. The function takes a string with the extension name as a parameter and returns true if the extension is active, or false if it is not loaded.

Syntax

phpextension_loaded(string $extension): bool

Example

Let's check if the "json" extension is loaded:

php<?php
  $res = extension_loaded('json');
  var_dump($res);
?>

Code execution result:

phptrue

Example

Let's check the availability of the "gd" extension:

php<?php
  if (extension_loaded('gd')) {
    echo 'GD extension is loaded';
  } else {
    echo 'GD extension is NOT loaded';
  }
?>

Code execution result:

php'GD extension is loaded'

See Also