dongyimeng3764 2009-09-15 20:10
浏览 17
已采纳

PHP4 - “致命错误:无法重新声明函数()”

Second time I've ran into this...

I have function foo() that has a helper function inside called formatStr() which is used in an array_map() call. When I call foo() more than once within a script I get a "Fatal error: Cannot redelcare formatStr()". Which leads me to believe formatStr() is not declared locally in the function but globally. Is this true? Can you get around this with function_exists()?

Thanks

  • 写回答

1条回答 默认 最新

  • dpxua26604 2009-09-15 20:15
    关注

    You have a function defined within the foo() function? If so, move it out.

    Otherwise, just wrap formatStr() within function_exists()...

    if (!function_exists('formatStr'))
    {
        function formatStr()
        {
            // Your function code
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?