Reputation: 3215
I would like to have the freedom of redeclaring particular functions in PHP. In another words, I have script that includes some files:
include_once(dirname(__FILE__) . '/../drupal/includes/bootstrap.inc');
include_once(dirname(__FILE__) . '/../drupal/includes/common.inc');
Later on in this script execution depending on some conditions, it is clear we need to load all application and not only particular files, however. This causes the error of redeclaration because when bootstrapping full App some of the functions were already included at beginning(i.e. bootstrap.inc, common.inc). What is solution? Can a remove an imported file before including it again to avoid redeclaration error? Can i have control on deciding when its okey to redeclare and when not in PHP? Thank you for help
Upvotes: 0
Views: 1737
Reputation: 31614
You can't "uninclude" a file. Once it's in, it's in.
Typically an include_once
or require_once
will do the trick. PHP will check to see if it's already included before trying to include it again. I would make sure that's being used in all locations. If the functions you're calling are inside a class, I would check out autoloading as a way to help manage your includes.
Upvotes: 3