Jump to content

Archived

This topic is now archived and is closed to further replies.

HGeneAnthony

Error using require in more than one file

Recommended Posts

When I write code/script I generally rely heavily on classes and create a class in every file which shares the same name as the file (due to my Java background). For example, search.php has a Search class. Well sometimes my classes need to call each other so I have to include the file in every file which calls the class in it. For example require("search.php"); for classes which call my Search class. However, I've had errors where if I require a class in more than one file PHP shoots out an error saying I can't require it more than once. However, I have 2 classes in 2 different files that need to use the class. If I don't specify require in either one I get errors saying it can't find the class. How can I work around this.

Share this post


Link to post
Share on other sites
[!--quoteo(post=380066:date=Jun 4 2006, 11:08 PM:name=HGeneAnthony)--][div class=\'quotetop\']QUOTE(HGeneAnthony @ Jun 4 2006, 11:08 PM) [snapback]380066[/snapback][/div][div class=\'quotemain\'][!--quotec--]
When I write code/script I generally rely heavily on classes and create a class in every file which shares the same name as the file (due to my Java background). For example, search.php has a Search class. Well sometimes my classes need to call each other so I have to include the file in every file which calls the class in it. For example require("search.php"); for classes which call my Search class. However, I've had errors where if I require a class in more than one file PHP shoots out an error saying I can't require it more than once. However, I have 2 classes in 2 different files that need to use the class. If I don't specify require in either one I get errors saying it can't find the class. How can I work around this.
[/quote]

what about include("whatever.php");

Share this post


Link to post
Share on other sites
Use require_once().

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.