Content · Programming · PHP

PHP get_loaded_extensions() Function: Usage and Examples

Understand PHP get_loaded_extensions() with three examples, return behavior, important pitfalls, and related operations.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Use get_loaded_extensions() when you need to lists extensions loaded into the current PHP runtime in a PHP application. The examples below show the actual operation and its limitations.

What Is get_loaded_extensions() in PHP?

Lists extensions loaded into the current PHP runtime. The exact signature supported by your installation depends on its PHP version and enabled extensions.

Its syntax is:

get_loaded_extensions(bool $zend_extensions = ...): array

Parameters and return value: The parameter types, optional arguments, references, and return type are shown in the signature above. Optional parameters are marked with an ellipsis in this reference signature.

Example 1: Basic Usage

<?php

$extensions = get_loaded_extensions(); echo in_array("standard", $extensions, true) ? "Standard loaded" : "Missing";

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Example 2: Different Input or Behavior

<?php

echo count(get_loaded_extensions()) > 0 ? "Extensions available" : "None";

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Practical Example: Applying the Function

<?php

$requiredExtensions = ["json","openssl"]; $loaded = array_map("strtolower", get_loaded_extensions()); foreach ($requiredExtensions as $extension) echo $extension . ": " . (in_array($extension,$loaded,true) ? "yes" : "no") . PHP_EOL;

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Important Behavior and Edge Cases

Loaded modules differ between CLI and web SAPIs; check the environment used in production.

Comparison With Related Functions

ApproachDifference
get_loaded_extensions()Lists extensions loaded into the current PHP runtime.
Related operationextension_loaded() checks one extension; get_loaded_extensions() lists them all.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the function-specific limitationLoaded modules differ between CLI and web SAPIs; check the environment used in production.
Confusing this function with a related operationextension_loaded() checks one extension; get_loaded_extensions() lists them all.

Key Takeaways

  • Lists extensions loaded into the current PHP runtime.
  • Loaded modules differ between CLI and web SAPIs; check the environment used in production.
  • extension_loaded() checks one extension; get_loaded_extensions() lists them all.

Use get_loaded_extensions() for the specific operation demonstrated above. Check its prerequisites and handle failure conditions before using it with production data.

Share this resourceSend this page to someone who may find it useful.