owen

Our next issue is namespaces. I’ve written some information about this in the codex. This project is probably a little small to be worrying about namespace collisions, but it merits mention so that you can use good practices when you move onto bigger things.

When you write a function in PHP, generally it exists in the global namespace. That means that you ca call that function from anywhere. It is not possible to declare two functions in the global namespace with the same name in PHP. If you and your friend write plugins to do similar things, you should’t use the same function names. But if you want to write a plugin that doesn’t share function names with people you haven’t met, how do you do that?

Use a class scope. Classes are one of the more complicated aspects of modern programming. Rather than try to explain theory and use like I would if you were sitting in front of me, I’ll summarize/simplify it like this: Functions that are declared in classes exist in their own namespace. Basically, you wrap this “class” around your functions, and then whenever you want to call the function, you specify both the class name and the function name. Usually pretty simple.