Funkce get_defined_functions

Funkce get_defined_functions vrací vícerozměrné pole obsahující seznam všech definovaných funkcí. Pole obsahuje dva klíče: 'internal' pro vestavěné funkce PHP a 'user' pro uživatelské funkce. Funkce nepřijímá parametry.

Syntaxe

phpget_defined_functions();

Příklad

Získáme seznam všech definovaných funkcí:

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

Výsledek provedení kódu (příklad):

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

Příklad

Zkontrolujeme existenci konkrétní funkce:

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

Výsledek provedení kódu:

php'Function strpos exists'

Příklad

Spočítáme množství uživatelských funkcí:

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

Výsledek provedení kódu:

php'User functions count: 2'

Viz také