get_defined_functions
Returns every defined function name, split into internal and user-defined lists.
get_defined_functions(bool $exclude_disabled = true): array- Added in PHP 4.0.4
Parameters
| Parameter | Type | Description |
|---|---|---|
$exclude_disabledoptional | bool= true | Whether disabled functions should be excluded. Has had no effect since PHP 8.0 and is deprecated as of PHP 8.5. |
Return value
arrayAn array with two keys: "internal" holding the names of built-in functions and "user" holding the names of user-defined ones. All names are lowercase.
Errors
Throws a TypeError if the argument is not a bool or cannot be coerced to one.
Changelog
- PHP 8.5The exclude_disabled parameter has been deprecated, as it no longer has any effect. Passing it raises an E_DEPRECATED notice.
- PHP 8.0The default value of exclude_disabled changed from false to true, but it has no effect because disabled functions are removed from the function table at compile time.
- PHP 7.1.1The exclude_disabled parameter was added (also backported to 7.0.15).
get_defined_functions() is introspection: it dumps the whole function table as two flat lists, ['internal'] for built-ins and ['user'] for everything declared by PHP code, including anything pulled in by autoloaded files or eval().
What it is actually good for
Diagnostics and tooling. Printing the user list from an error handler shows which of your files got loaded. Filtering the internal list by prefix tells you what an extension registered. A test that snapshots the user list before and after including a file catches accidental global function declarations. It is also handy when writing a build script that must confirm a set of helpers is present.
Do not use it for feature detection
Searching the returned array with in_array() to see whether one function exists is slower and more fragile than calling function_exists(), which is a direct hash lookup.
Two things that surprise people
Every name comes back lowercase, because the arrays are built from the function table's keys. A function declared as myHelper() appears as myhelper. And the exclude_disabled argument has done nothing since PHP 8.0; passing it on PHP 8.5 raises a deprecation notice, so call the function with no arguments.
Example
When to use it
- Dumping the list of user-defined functions from a debug page to see which files were loaded
- Listing every function an extension registered by filtering the internal list on its prefix
- Asserting in a test that including a file declares exactly the helpers it should and nothing more
- Building an audit script that reports how many built-in functions a given PHP build exposes
Frequently asked questions
How do I list all functions defined in my own code?
Read the "user" key of the returned array: get_defined_functions()['user']. It contains every function declared by PHP code, including ones from included and autoloaded files, in lowercase.
Why are the function names lowercase?
The arrays are built directly from PHP's internal function table, whose keys are lowercased because function names are case-insensitive. Lowercase your search string before comparing.
Should I use get_defined_functions to check if a function exists?
No. function_exists() is a single hash lookup, while this builds an array of thousands of strings that you then have to search. Use it for listing and diagnostics, not for existence checks.
More examples
Finding every function with a given prefix
Prints the array_diff family — array_diff, array_diff_assoc, array_diff_key, array_diff_uassoc, array_diff_ukey — in alphabetical order. Because the list is a plain array of strings, ordinary array functions are all you need to explore what a build provides.
<?php
$internal = get_defined_functions()['internal'];
$diffFns = array_values(array_filter($internal, fn(string $f): bool => str_starts_with($f, 'array_di')));
sort($diffFns);
print_r($diffFns);
echo 'total internal functions: ', count($internal) > 0 ? 'many' : 'none', "\n";Names are lowercased
Prints false, true, true. The exact-case search fails because the returned names come from the function table keys, which are lowercase. function_exists() has no such problem, which is another reason to prefer it for existence checks.
<?php
function MyCamelCaseHelper(): void {}
$user = get_defined_functions()['user'];
var_dump(in_array('MyCamelCaseHelper', $user, true));
var_dump(in_array('mycamelcasehelper', $user, true));
var_dump(function_exists('MyCamelCaseHelper'));The deprecated parameter
On PHP 8.5 the second call prints a deprecation notice saying the $exclude_disabled parameter has no effect since PHP 8.0, and the counts still match. Call the function with no arguments to keep the notice out of your logs.
<?php
set_error_handler(function (int $no, string $msg): bool {
echo "notice($no): $msg\n";
return true;
});
$a = get_defined_functions();
$b = get_defined_functions(true);
echo count($a['internal']) === count($b['internal']) ? "identical result\n" : "different\n";
Discussion