PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Selectively including classes Posted by ITA on 24 Mar 2005 at 9:54 AM
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,

ITA
"Let us smite the evil slime eating hordes who may befall us on our quest to be the ultimate programmers of the known universe!"
Report
Re: Selectively including classes Posted by netgert on 25 Mar 2005 at 1:03 AM
: 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,
:
: ITA
: "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,
http://ee.php.net/manual/en/language.oop5.autoload.php

NetGert[/italic]


Report
Re: Selectively including classes Posted by ITA on 25 Mar 2005 at 3:13 AM
thx a million. No more deps!

ITA


"Let us smite the evil slime eating hordes who may befall us on our quest to be the ultimate programmers of the known universe!"




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.