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

phpget_defined_functions();

Example

Get a list of all defined functions:

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

Code execution result (example):

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

Example

Check for the existence of a specific function:

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

Code execution result:

php'Function strpos exists'

Example

Count the number of user functions:

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

Code execution result:

php'User functions count: 2'

See Also