HGeneAnthony Posted June 4, 2006 Share Posted June 4, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11199-error-using-require-in-more-than-one-file/ Share on other sites More sharing options...
redarrow Posted June 4, 2006 Share Posted June 4, 2006 [!--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"); Quote Link to comment https://forums.phpfreaks.com/topic/11199-error-using-require-in-more-than-one-file/#findComment-41893 Share on other sites More sharing options...
HGeneAnthony Posted June 4, 2006 Author Share Posted June 4, 2006 I'll try it but why would it be any different than require in this instance? Quote Link to comment https://forums.phpfreaks.com/topic/11199-error-using-require-in-more-than-one-file/#findComment-41894 Share on other sites More sharing options...
trq Posted June 4, 2006 Share Posted June 4, 2006 Use require_once(). Quote Link to comment https://forums.phpfreaks.com/topic/11199-error-using-require-in-more-than-one-file/#findComment-41895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.