PHP Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    PHP Function

    Hey guys, I am pretty sure this is how it works but I just want to confirm it:
    If I declare a function, what's in the function is only run if the function is called? I am planning on having a "function file" which will be called on every page and contain my entire site's functions. The alternative is to include page-specific functions, but if there is no difference then I will just always have all of them there?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by TheServant
    If I declare a function, what's in the function is only run if the function is called?
    yes. additionally, there are some magic methods* which are run depending on a condition/event.

    Originally posted by TheServant
    I am planning on having a "function file" which will be called on every page and contain my entire site's functions.
    that's commonly called a function library.

    Originally posted by TheServant
    The alternative is to include page-specific functions, but if there is no difference then I will just always have all of them there?
    if you're doing object oriented programming, you can make use of the __autoload() function (resp. spl_autoload_re gister()). These functions will load only the classes you need.

    * __construct(), __destruct(), __get(), __set(), __call(), __sleep(), __wakeup(), __clone(), __autoload() to name maybe the most common.

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      lol, I had come across the name function library before, but coudln't remember the phrase. Thanks for your help again ;)

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        I prefer to call them 'helpers', or rather CodeIgniter would have me call them that.

        Comment

        Working...