tags:

views:

182

answers:

1

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  A: 

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
    }
}
Matt
I know, but it seems wrong to muck up the global name space with a helper function. I guess I will have to wait to we upgrade to PHP5 so I can use anonymous functions. Thanks.
frio80