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
| Function | Purpose |
|---|---|
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
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: This checks installation but not necessarily configuration or service readiness | This 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.