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
get_defined_functions();
Příklad
Získáme seznam všech definovaných funkcí:
<?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):
[
'zend_version',
'func_num_args',
'func_get_args'
]
['customFunction']
Příklad
Zkontrolujeme existenci konkrétní funkce:
<?php
$functions = get_defined_functions();
if (in_array('strpos', $functions['internal'])) {
echo 'Function strpos exists';
}
?>
Výsledek provedení kódu:
'Function strpos exists'
Příklad
Spočítáme množství uživatelských funkcí:
<?php
function func1() {}
function func2() {}
$res = get_defined_functions();
echo 'User functions count: ' . count($res['user']);
?>
Výsledek provedení kódu:
'User functions count: 2'
Viz také
-
funkci
function_exists,
která kontroluje existenci konkrétní funkce -
funkci
get_defined_constants,
která vrací všechny definované konstanty