PHP - function_exists() 函式



如果給定的函式已定義,則 function_exists() 函式可以返回 true。

語法

bool function_exists( string $function_name )

function_exists() 函式可以檢查已定義函式的列表,包括內建(內部)函式和使用者定義的函式 function_name。如果 function_name 存在,則此函式可以返回 true,否則返回 false。

示例

<?php
    $function_name = "fopen";
    if (function_exists($function_name) ) {
        echo "$function_name is enabled";
    } else {
       echo "$function_name is not enabled";
    }
?>

輸出

fopen is enabled
php_function_reference.htm
廣告