曲径通幽论坛

标题: function_exists() -- 判断函数是否定义过 [打印本页]

作者: beyes    时间: 2012-6-25 19:22
标题: function_exists() -- 判断函数是否定义过
function_exists() 函数用以判断函数是否被定义过,语法如下:
[Plain Text] 纯文本查看 复制代码
bool function_exists ( string $function_name )

如果被定义过,函数返回 TRUE;否则返回 FALSE 。

测试代码:
[PHP] 纯文本查看 复制代码
<?php
        function myfunc1() {
                echo "hello myfunc1";
        }


        if (function_exists('myfunc1'))
                echo "myfunc1() is defined." . "<br>";
        else
                echo "myfunc1() is not fefine." . "<br>";




        if (function_exists('myfunc2'))
                echo "myfunc2() is defined." . "<br>";
        else
                echo "myfunc2() is not fefine." . "<br>";
               
?>

运行输出:
myfunc1() is defined.
myfunc2() is not fefine.





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2