: I'm currently working on a project which contains many classes. Each class is written in a separate file. Each file which I work on has included classes in it. Some classes rely on others and those classes also include files. What I want to do is to stop receiving the "cannot redeclare class" error. Is there any way of doing this? (I can get rid of them, but I have to work out file dependencies and it's slooow).
: I'm thinking along the lines of the C++ '#ifndef and #include' directives to stop multiple includes.
: If this is not possible then, is there any way in which this can be done by writing a little code in PHP to check to see if the file has already been included by PHP and if so prevent it from being included again.
: Please help, (otherwise I'll have to spend ages trying to code round the problem
: Many thanks,
: "Let us smite the evil slime eating hordes who may befall us on our quest to be the ultimate programmers of the known universe!"
instead of include() use include_once() - this will not re-include an already included file
alteratively, you could write one classloader script that has if's and else's to decide which classes you want to load
if you're using PHP5 you might also want to check out how to autoload objects,