I'm trying to include many files containing functions, classes and calls but I would like to put everything in a PHP namespace. My issue is : all the files are part of another web application core. So I cannot edit the files. Is there a way tu declare a namespace globally for a list of files ? Something like that :
namespace mynamespace {
include_once("file1.inc.php");
include_once("file2.inc.php");
include_once("file3.inc.php");
...
}
Of course I tried this code and it does not work; all my tries failed while the first line of the include files where note namespace mynamespace;.
No, it is not possible. Every single file needs to declare its own namespace; you cannot force something to be in a different namespace using external code. (Some hacks like runkit or such will probably allow you to fiddle with that, but I'd consider this outside the regular scope of PHP as a language.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With