do you use php includes or requires?

4 replies
  • WEB DESIGN
  • |
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
.......\<,
....( )/ ( )...
#includes #php #requires
  • Profile picture of the author n7 Studios
    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.
    {{ DiscussionBoard.errors[1583879].message }}
  • Profile picture of the author mattalways
    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.
    Signature

    Quit wasting your money! If you need a website, get me to do it right! I'll probably even do it for less! Design/Development/Software, I'm your guy! matt@snidge.com
    {{ DiscussionBoard.errors[1584705].message }}
    • Profile picture of the author CarloD.
      Ya go with includes.
      Signature

      {{ DiscussionBoard.errors[1584743].message }}
  • Profile picture of the author LenD
    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
    {{ DiscussionBoard.errors[1586980].message }}

Trending Topics