Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Website Design
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 01-06-2010, 11:53 AM   #1
copy and paste geek
War Room Member
 
Join Date: Jan 2005
Location: Calgary
Posts: 1,390
Thanks: 68
Thanked 168 Times in 140 Posts
Default do you use php includes or requires?

W3schools mentions that you should always use the "requires because scripts should not continue after an error."

I haven't seen this mentioned anywhere else. Is this something that doesn't make a gnat worth of difference?

Also I have WAMP installed now. My first include wouldn't work but when I uploaded it to a host it worked fine. I tried to double click on the WampServer icon first, then on the .php page, but my include menu didn't show up. Tried quite a few times.

Any idea about what I or my machine might be doing wrong?

best wishes, lloyd
.......__o
.......\<,
....( )/ ( )...

There are 10 types of people, those that understand binary and those that don't.
The KimW WSO
Lloyd Buchinski is offline   Reply With Quote
Old 01-06-2010, 12:02 PM   #2
Web Developer, IT Support
War Room Member
 
n7 Studios's Avatar
 
Join Date: Dec 2008
Location: Birmingham, UK
Posts: 513
Thanks: 10
Thanked 77 Times in 65 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile 
Default Re: do you use php includes or requires?

require() produces a fatal error if the file cannot be found, therefore stopping any further script execution

include() produces a warning if the file cannot be found, but does not stop further script execution

It's your choice which you use based on the scenario you're coding for - you wouldn't want to use include() if the file you're including has functions which you then later assume in your coding are available to call, otherwise you'll get a host of errors.

n7 Studios is offline   Reply With Quote
Old 01-06-2010, 02:43 PM   #3
HyperActive Warrior
 
mattalways's Avatar
 
Join Date: Jan 2010
Location: Ontario, Canada
Posts: 279
Thanks: 1
Thanked 21 Times in 20 Posts
Default Re: do you use php includes or requires?

I use include(); Works like a charm!

It's great to make w3 compliant code, but they go a bit crazy at times. I'm not really sure how these two will make any difference to your overall output.
mattalways is offline   Reply With Quote
Old 01-06-2010, 02:52 PM   #4
HyperActive Warrior
War Room Member
 
CarloD.'s Avatar
 
Join Date: Dec 2009
Location: Thunder Bay ON
Posts: 401
Thanks: 12
Thanked 42 Times in 36 Posts
Social Networking View Member's YouTube Profile
Contact Info
Send a message via Skype™ to CarloD.
Default Re: do you use php includes or requires?

Ya go with includes.
CarloD. is offline   Reply With Quote
Old 01-07-2010, 12:42 AM   #5
Old Dog -- New Tricks
 
LenD's Avatar
 
Join Date: Jan 2010
Location: Florida
Posts: 19
Thanks: 1
Thanked 8 Times in 5 Posts
Social Networking View Member's FaceBook Profile 
Contact Info
Send a message via MSN to LenD Send a message via Skype™ to LenD
Default Re: do you use php includes or requires?

Quote:
Originally Posted by Lloyd Buchinski View Post
W3schools mentions that you should always use the "requires because scripts should not continue after an error."
Here's what you need to consider. What is the purpose of the include file? If it's providing your database connection string, or some global variables that are needed by other scripts, then the script is going to fail anyway.

What if the include loads your navigation menu and it fails for some reason? Does your site become unusable as a result.

If you want to differentiate between when you use include and require, I'd use this rule of thumb:

If a failure results in cosmetic errors only, like a log or footer failing to load, no big deal. Use 'include'

If the failure would result in the site not being usable, 'require' it.

I just use require all the time, but that's my choice.

Len
LenD is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Website Design

Tags
includes, php, requires

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 02:38 AM.