Jump to content


Photo

Error using require in more than one file


  • Please log in to reply
3 replies to this topic

#1 HGeneAnthony

HGeneAnthony
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 04 June 2006 - 11:08 PM

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.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 June 2006 - 11:13 PM

[!--quoteo(post=380066:date=Jun 4 2006, 11:08 PM:name=HGeneAnthony)--][div class=\'quotetop\']QUOTE(HGeneAnthony @ Jun 4 2006, 11:08 PM) View Post[/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");
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 HGeneAnthony

HGeneAnthony
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 04 June 2006 - 11:16 PM

I'll try it but why would it be any different than require in this instance?

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 June 2006 - 11:17 PM

Use require_once().




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users