Funksie get_defined_functions
Die funksie get_defined_functions gee 'n multidimensionele versameling terug wat 'n
lys van alle gedefinieerde funksies bevat. Die versameling bevat twee sleutels: 'internal' vir ingeboude
PHP-funksies en 'user' vir gebruiker-funksies. Die funksie neem geen parameters aan nie.
Sintaksis
get_defined_functions();
Voorbeeld
Kry 'n lys van alle gedefinieerde funksies:
<?php
function customFunction() {}
$res = get_defined_functions();
print_r(array_slice($res['internal'], 0, 3));
print_r($res['user']);
?>
Uitvoerresultaat (voorbeeld):
[
'zend_version',
'func_num_args',
'func_get_args'
]
['customFunction']
Voorbeeld
Kontroleer die bestaan van 'n spesifieke funksie:
<?php
$functions = get_defined_functions();
if (in_array('strpos', $functions['internal'])) {
echo 'Funksie strpos bestaan';
}
?>
Uitvoerresultaat:
'Funksie strpos bestaan'
Voorbeeld
Tel die aantal gebruiker-funksies:
<?php
function func1() {}
function func2() {}
$res = get_defined_functions();
echo 'Aantal gebruiker-funksies: ' . count($res['user']);
?>
Uitvoerresultaat:
'Aantal gebruiker-funksies: 2'
Sien ook
-
die funksie
function_exists,
wat die bestaan van 'n spesifieke funksie kontroleer -
die funksie
get_defined_constants,
wat alle gedefinieerde konstantes teruggee