SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include(), include_once() ...

    Just curious.. wouldn't the best approach be to always use include_once() (as well require_once()) to ALWAYS be sure that if you by accident have already included a file before it won't get included again. I just don't understand why you should use include() when the "better" version exists? Or is the include_once() function significantly more processor heavy so it should be used with care?

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Include_once() is to prevent variables, functions, and classes from being declared twice by possibly including the same code again.

    Also, lets ssume you have a for loop which includes a message thats output on the page, if you wanted that message to repeat each time the loop circled you'd have to use include, using include_once would only allow the message once.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Location
    Gothenburg, Sweden
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So basically it's safe to say in 90% of the occations I can use the include_once() function?

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pcw View Post
    So basically it's safe to say in 90% of the occations I can use the include_once() function?
    Well, it does exactly as it says on the tin, if you only ever want the include to run once, yes go ahead.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •