Possible Duplicate:
Removing a function at runtime in PHP
I have a script that is including different files while running. The files all contain a function with the same name. I only need the currently included to exist. Is there any way to enable dynamic file including, so it won’t be causing Fatal error: Cannot redeclare function()?
In another words I need to either rename or remove the previous function.
The function is declared in a classical way function fn(){;}
Rather than each file defining a top-level function with the same name, consider using a very simple OO structure:
Assuming you have something like this:
You could replace it with something like this:
And then in each of the included files, instead of one function, you would define a class containing that function, like this:
Not only does this solve your problem, it puts you on the road to learning other advanced/OO PHP techniques – autoloading the files so you don’t have to specify
include_onceevery time, defining hierarchies and interfaces, etc.