Is it possible to define the same function in two files, include them and then call both function in one go, e.g.
== File1.php ==
function my_function() {
echo "File 1!";
}
== File2.php ==
function my_function() {
echo "File 2!";
}
== File3.php ==
include('File1.php');
include('File2.php');
my_function();
–
Which would output:
File 1!
File 2!
Is this is not possible how would I work around that?
Thanks,
Thomas Edwards
You can’t redefine global functions (outside of runkit, but that’s bad voodoo) so your options remain of using a class driven solution, or an anonymous function driven solution as follows.
You could write a function to assemble all included functions into a call queue (which is simply another anonymous function that runs the queue):
And return anonymous functions from each of the files as you described, rather than redefine a global function:
file1.php
file2.php
Then, you can: