These are a few notes to myself about managing directory paths in PHP. Unlike other programming environments, PHP doesn't hide the ugliness of file paths too well. Consequently, the programmer must spend effort to organize the file hierarchy, and manage paths.
There are a few directory paths that are handy to know:
There are a few extra directories to add for an app framework:
Also, it's best to create some rules about passing paths as arguments into functions. Here are my rules:
These rules just keep me from writing code like this: $path = $path1 . '/' . $path2, and losing track of whether there's a slash at the end of the path or not. Despite my better judgment, I use the literal '/' instead of the DIRECTORY_SEPARATOR constant. This'll change in my code over time. The hardest part is writing this:
$path = rtrim(DIRECTORY_SEPARATOR,$path).DIRECTORY_SEPARATOR;