Content · Programming · PHP

PHP function_exists() Function: Usage and Examples

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

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

Use function_exists() when you need to checks whether a function has been defined and is callable by name in a PHP application. The examples below show the actual operation and its limitations.

What Is function_exists() in PHP?

Checks whether a function has been defined and is callable by name. The exact signature supported by your installation depends on its PHP version and enabled extensions.

Its syntax is:

function_exists(string $function): bool

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

var_dump(function_exists("strlen"));

Output:

bool(true)

Example 2: Different Input or Behavior

<?php

var_dump(function_exists("not_a_real_function_xyz"));

Output:

bool(false)

Practical Example: Applying the Function

<?php

$optionalFeatures = ["mb_strlen", "iconv_strlen"]; foreach ($optionalFeatures as $feature) echo $feature . ": " . (function_exists($feature) ? "available" : "missing") . PHP_EOL;

Output:

mb_strlen: missing
iconv_strlen: available

Important Behavior and Edge Cases

It does not prove that an extension is enabled for a particular operation or that a call will succeed.

Comparison With Related Functions

ApproachDifference
function_exists()Checks whether a function has been defined and is callable by name.
Related operationis_callable() also checks callable syntax and methods; function_exists() checks functions by name.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the function-specific limitationIt does not prove that an extension is enabled for a particular operation or that a call will succeed.
Confusing this function with a related operationis_callable() also checks callable syntax and methods; function_exists() checks functions by name.

Key Takeaways

  • Checks whether a function has been defined and is callable by name.
  • It does not prove that an extension is enabled for a particular operation or that a call will succeed.
  • is_callable() also checks callable syntax and methods; function_exists() checks functions by name.

Use function_exists() 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.