Content · Programming · PHP

PHP extension_loaded() Function: Usage and Examples

Learn how PHP extension_loaded works with practical examples, important behavior, relevant alternatives and common mistakes.

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

Checks whether a named extension is loaded in the current PHP runtime.

What Is extension_loaded() in PHP?

Checks whether a named extension is loaded in the current PHP runtime.

Its syntax is:

extension_loaded(string $extension): bool

Parameters:

  • $extension — Accepted as string; required argument.

Return type: bool. This checks installation but not necessarily configuration or service readiness.

Availability: Core PHP.

Example 1: Basic Usage

<?php

var_dump(extension_loaded("json"));

Output:

bool(true)

This checks installation but not necessarily configuration or service readiness.

Example 2: A Different Input

<?php

var_dump(extension_loaded("nonexistent_extension"));

Output:

bool(false)

This checks installation but not necessarily configuration or service readiness.

Practical Example: Applying It in a Program

<?php

$optionalFeatures = ["intl", "mbstring", "curl"]; foreach ($optionalFeatures as $extensionName) { echo $extensionName . ": " . (extension_loaded($extensionName) ? "ready" : "missing") . PHP_EOL; }

Output:

intl: missing
mbstring: missing
curl: missing

This checks installation but not necessarily configuration or service readiness.

Important Behavior and Edge Cases

  • Key behavior: This checks installation but not necessarily configuration or service readiness.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
extension_loaded()Checks whether a named extension is loaded in the current PHP runtime.
get_loaded_extensions()get_loaded_extensions() lists loaded extensions; extension_loaded() checks for one specific extension.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: This checks installation but not necessarily configuration or service readinessThis checks installation but not necessarily configuration or service readiness.

Key Takeaways

  • Checks whether a named extension is loaded in the current PHP runtime.
  • This checks installation but not necessarily configuration or service readiness.
  • Core PHP.

Summary: This checks installation but not necessarily configuration or service readiness.

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