Alex Rivera | Logout

PHP: how to avoid redeclaring functions?

Asked 2009-09-05T18:46:48.740
45

I tend to get errors such as:

Fatal error: Cannot redeclare get_raw_data_list() (previously declared in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php:7) in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php on line 19

how can I avoid the error? Is it possible to create a IF-clause to check whether a function is declared before declaring it?

Edit
Report

1 Answer

5

If you are dealing with Classes method_exists() might be what you're looking for:

if(!method_exists(__CLASS__, 'function_name')){
    function function_name(){

    }
}

This will check the current Class to make that the function function_name doesn't exist before trying to declare it

answered 2012-06-16T05:09:15.473

Your Answer