関数 get_defined_functions
関数 get_defined_functions は、定義済みのすべての関数のリストを含む多次元配列を返します。
配列には2つのキーがあります: PHPの組み込み関数用の 'internal' とユーザー定義関数用の 'user' です。
この関数はパラメータを受け取りません。
構文
get_defined_functions();
例
定義済みのすべての関数のリストを取得します:
<?php
function customFunction() {}
$res = get_defined_functions();
print_r(array_slice($res['internal'], 0, 3));
print_r($res['user']);
?>
コードの実行結果 (例):
[
'zend_version',
'func_num_args',
'func_get_args'
]
['customFunction']
例
特定の関数の存在を確認します:
<?php
$functions = get_defined_functions();
if (in_array('strpos', $functions['internal'])) {
echo 'Function strpos exists';
}
?>
コードの実行結果:
'Function strpos exists'
例
ユーザー定義関数の数を数えます:
<?php
function func1() {}
function func2() {}
$res = get_defined_functions();
echo 'User functions count: ' . count($res['user']);
?>
コードの実行結果:
'User functions count: 2'
関連項目
-
特定の関数の存在をチェックする関数
function_exists -
定義済みのすべての定数を返す関数
get_defined_constants