Content · Programming · PHP

PHP get_defined_functions() Function: Usage and Examples

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

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

Use get_defined_functions() when you need to returns the functions currently defined in PHP in a PHP application. The examples below show the actual operation and its limitations.

What Is get_defined_functions() in PHP?

Returns the functions currently defined in PHP. The exact signature supported by your installation depends on its PHP version and enabled extensions.

Its syntax is:

get_defined_functions(bool $exclude_disabled = ...): array

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

$functions = get_defined_functions(); echo in_array("strlen", $functions["internal"], true) ? "Available" : "Missing";

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Example 2: Different Input or Behavior

<?php

$functions = get_defined_functions(); echo count($functions["internal"]) > 0 ? "Internal functions found" : "None";

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Practical Example: Applying the Function

<?php

$defined = get_defined_functions(); $matches = array_filter($defined["internal"], fn($name) => str_starts_with($name,"json_")); echo count($matches) . " JSON functions";

Result: Run the example in an environment that supports the function. Any values depending on operating-system state, installed extensions, process configuration, or network access must be checked on the target server.

Important Behavior and Edge Cases

Installed extensions affect the list; counts differ between systems.

Comparison With Related Functions

ApproachDifference
get_defined_functions()Returns the functions currently defined in PHP.
Related operationfunction_exists() tests one function; get_defined_functions() enumerates functions.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the function-specific limitationInstalled extensions affect the list; counts differ between systems.
Confusing this function with a related operationfunction_exists() tests one function; get_defined_functions() enumerates functions.

Key Takeaways

  • Returns the functions currently defined in PHP.
  • Installed extensions affect the list; counts differ between systems.
  • function_exists() tests one function; get_defined_functions() enumerates functions.

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