Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

function_exists

Checks whether a function is defined.

Syntax

function_exists(string $function): bool

Parameters

ParameterTypeDescription
$functionstringThe function name.

Return value

bool`true` if the function exists.

Examples

A built-in and a missing function:

<?php
 
var_dump(function_exists('strlen'));
var_dump(function_exists('no_such_function'));

Output:

bool(true)
bool(false)

Checking that an extension is available:

<?php
 
echo function_exists('mb_strlen') ? 'mbstring is available' : 'mbstring is missing';

Output:

mbstring is available

Notes

This is how you check that a PHP extension is installed before using its functions.

See also

Related recipes

In the tutorial

Thanks for reading!

Donate to the site — we work hard for you.