I’m attempting to utilize a 3rd-party PHP library in a semi-developed web project. Unfortunately, as I am beginning to use the 3rd party code, I’m realizing that there is a number of variable and class name collisions. I was curious to know if there existed a strategy to retrofit a namespace around this new code.
…and yes, there’s equal blame to be passed onto myself for not utilizing namespaces, as well.
Off the top of my head I am considering editing every .php file and adding:
namespace facePalm;
But I was curious to know if there happened to be a more elegant solution. Especially as additional revisions of the code are released, I would rather not have to touch & edit 30+ files.
A namespace is set for one file only, and a file can only contain 1 namespace. I’m afraid you don’t have other solutions to do it.
[edit] I just checked and one file can contain multiple namespaces. But you can’t have a namespace in a file without defining it at the top of it.