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
| Approach | Difference |
|---|---|
get_defined_functions() | Returns the functions currently defined in PHP. |
| Related operation | function_exists() tests one function; get_defined_functions() enumerates functions. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring the function-specific limitation | Installed extensions affect the list; counts differ between systems. |
| Confusing this function with a related operation | function_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.