This is how i implemented import and namespaces in PHP. obviously this is very limited, as its not part of the language, but it does provide a simple way of organizing classes. Now if you were really tricky and were using PHP 5 (as i am), you could mess with your naming sceme and __autoload() to get the same results with one less user-typed function call, but i think import looks cooler 😉.
In any case, i know it may seem kind of boring, but after reading a post about something like this implemented in the engine, i decided to write it to be as extensible as possible (set the first param to false and you have 3 init options: base directory, namespace delimeter character, and error out level (that's some code ripped from the token_name() user notes)).
enjoy another pointless piece of code by Moonglobe 🙂
[edit]Forgot a few things, and also added support for single file inclusion without a one-file directory. here's what i forgot to say:
if any of the included files spit anything out, then the function checks if there is "error" (case-insensitive) in the text. if so, it lets it show up, if not, it cuts it (this is because im often too lazy to take out the debugging code at the bottom of my class definition scripts :p). Also now, if there's not a directory that matches the namespace, the last namespace has '.php' tacked on and there's a check to see if that file exists. This functionality is turned off by default though, you have to pass true to the 5th param during init to get that operational.[/edit]