393 of 410 menu

The get_defined_functions Function

The get_defined_functions function returns a multidimensional array containing a list of all defined functions. The array contains two keys: 'internal' for built-in PHP functions and 'user' for user-defined functions. The function does not accept parameters.

Syntax

get_defined_functions();

Example

Get a list of all defined functions:

<?php function customFunction() {} $res = get_defined_functions(); print_r(array_slice($res['internal'], 0, 3)); print_r($res['user']); ?>

Code execution result (example):

[ 'zend_version', 'func_num_args', 'func_get_args' ] ['customFunction']

Example

Check for the existence of a specific function:

<?php $functions = get_defined_functions(); if (in_array('strpos', $functions['internal'])) { echo 'Function strpos exists'; } ?>

Code execution result:

'Function strpos exists'

Example

Count the number of user functions:

<?php function func1() {} function func2() {} $res = get_defined_functions(); echo 'User functions count: ' . count($res['user']); ?>

Code execution result:

'User functions count: 2'

See Also

byenru