PHP Spotlight: get_loaded_extensions()

Written by NewTrick

21 Jul 2025

#PHP

An illustration of a stuffed PHP elephant placed on the keyboard of a laptop.

Today's spotlight looks at a couple of very useful PHP functions  that can help if you are running multiple PHP versions, working on unfamiliar set ups, or want to know more about what functions are available in your PHP installation.

These functions are get_loaded_extensions(), extension_loaded(), and get_extension_funcs().

get_loaded_extensions()

 

We can use get_loaded_extensions() to find out which PHP extensions we have loaded before we examine the functions used in that extension.

As per the docs, we can simply use print_r() to output the extensions used in your PHP installation.

<?php
print_r(get_loaded_extensions());
?>


This will output an array of extensions in use:

Array
(
   [0] => Core
   [1] => date
   [2] => libxml
   [3] => openssl
   [4] => pcre
   [5] => sqlite3
   [6] => zlib
   [7] => bcmath
   [8] => bz2
   [9] => calendar
   [10] => ctype
   [11] => curl    
   [12] => … 
   [43] => random
   ... rest of the modules
)

 

It's essentially a reduced version of phpinfo(), or the equivalent of phpinfo(INFO_MODULES);.

extension_loaded()

Alternatively, if you know the name of an extension, you can use extension_loaded('NAME_OF_EXTENSION'), which will return a boolean indicating whether the extension is available:

<?php
if(extension_loaded('random')) {
   echo ('Loaded');
}
//returns 'Loaded'
?>

 

get_extension_funcs()


Once you know the names of the extension, you can then check the functions available using get_extension_funcs(string $extension), which takes a lower-case name of an extension and returns an array of functions available.

<?php
print_r(get_exension_funcs('random'));
/*
 returns:
 Array
(
   [0] => lcg_value
   [1] => mt_srand
   [2] => srand
   [3] => rand
   [4] => mt_rand
   [5] => mt_getrandmax
   [6] => getrandmax
   [7] => random_bytes
   [8] => random_int
)
*/
?>

 

A useful to know what is available on your system, or to learn more about what is available in each extension.