Cyclone
Cyclone

Reputation: 15269

Skip function is it's declared already

First of all, I've used function_exists to check, if my function was previously declared but doesn't help.

This is my code:

if ( !function_exists('something') ) {
   function something($params) {
       [..]
   }
}

And when I enter to the page, which has declared this function twice, then the following error occurring: Fatal error: Cannot redeclare something() (previously declared in [..])

So the question is, how I can check, if the function exists already, and if it exists skip loading it twice?

Upvotes: 2

Views: 2640

Answers (1)

Notinlist
Notinlist

Reputation: 16640

if( !function_exists('something') ){
    require("something_definer.php");
}

Upvotes: 5

Related Questions