[PHP] function_exists - 함수가 있는지 알아보기

  function_exists 함수는 함수(fucntion)가 선언되었는지 아닌지를 알려준다.

  선언된 함수이면 bool 값으로 참(true)을 돌려주고, 선언되지 않은 함수이면 bool 값으로 거짓(false)을 돌려준다.

▣ 형식

  • function_exists(string $function): bool
    • 보기 : function_exists('함수 이름');

  대상 함수의 이름을 문자열로 넣는다.

▣ 보기

function funcA() {}
function funcB() { return true; }

$a = function_exists('funcA');
$b = function_exists('funcB');
$c = function_exists('funcC');

print('$a : '); var_dump($a); print('<br />');
print('$b : '); var_dump($b); print('<br />');
print('$c : '); var_dump($c); print('<br />');

▣ 출력 결과

$a : bool(true)
$b : bool(true)
$c : bool(false)

글 걸기 주소 : 이 글에는 글을 걸 수 없습니다.

덧글을 달아 주세요