Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

extension_loaded

Checks whether a PHP extension is loaded.

Syntax

extension_loaded(string $extension): bool

Parameters

ParameterTypeDescription
$extensionstringThe extension name: `mbstring`, `curl`, `pdo_mysql`, `gd`.

Return value

bool`true` if the extension is available.

Examples

Checking before use:

<?php
 
var_dump(extension_loaded('json'));
var_dump(extension_loaded('no_such_extension'));

Output:

bool(true)
bool(false)

Notes

The php -m command lists every extension. A project's requirements go into composer.json: "ext-mbstring": "*".

See also

Related recipes

In the tutorial

  • Namespaces and Composer — How a PHP project is organised — namespaces, PSR-4 class autoloading and installing libraries with Composer.

Thanks for reading!

Donate to the site — we work hard for you.