Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    159
    Thanks
    4
    Thanked 8 Times in 8 Posts

    PHP functions in one file

    Is it a bad idea to store all of my PHP functions in one file? Just have a single file with all my PHP functions in it and call the individual functions as I need them? Or would it be faster to put the each function directly into it's original file?

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    i prefer to have all of my functions split up into classes in separate files. then i load them as I need them using __autoload()


    http://php.net/manual/en/language.oop5.autoload.php

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Like angst, I split them up into different classes/files, but that's merely to categorise them and put them where I think they best belong. Having them in one file is as good as though. Just depends which is your personal preference.

  • #4
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    159
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Wouldn't having them in one file be slow? I mean, the server has to run through all the functions until it gets to the one it needs. And is _autoload() better than include()? What's the difference between them?

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    i would think that technically yes, if you have +100k lines of code in one file it might take a little longer to access the script. but I've never tested.

    also, __autoload uses includes, however with autoload it makes my class lib more dynamic. i can added classes and call them as i please without having to declare them in a settings file.


  •  

    Posting Permissions

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