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

phpget_defined_functions();

Voorbeeld

Kry 'n lys van alle gedefinieerde funksies:

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

Uitvoerresultaat (voorbeeld):

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

Voorbeeld

Kontroleer die bestaan van 'n spesifieke funksie:

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

Uitvoerresultaat:

php'Funksie strpos bestaan'

Voorbeeld

Tel die aantal gebruiker-funksies:

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

Uitvoerresultaat:

php'Aantal gebruiker-funksies: 2'

Sien ook