Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member spasm attack's Avatar
    Join Date
    Aug 2006
    Location
    Colorado
    Posts
    15
    Member #
    13735
    Hello, so I just finished up a book on PHP, but it was written for people who had some background in Perl/C++, although it said anyone could learn from it. I understood most of it, but there are some things I need clarified. The first is: can I define a list of functions in one *.php file, and then use them in another *.php without having to redefine them? Common sense tells me not without pointing the second file to the first one, but I don't know how. I was thinking about if I could use include(), but I think my book said something about an extension or something like that, but that was one of those things I couldn't understand. Is there an include() type function designed specifically for a list of functions?
    "There is no spoone" -The Matricks

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    If you include or require the file with your functions before you try and call a function listed in the file, that is fine.

    What you are maybe thinking of, is a .inc file. These are normally used for design aspects, such as having a header.inc and footer.inc file which you include on many pages throughout your website.

  4. #3
    Junior Member spasm attack's Avatar
    Join Date
    Aug 2006
    Location
    Colorado
    Posts
    15
    Member #
    13735
    If you include or require the file with your functions
    is there a difference between requiring and including? Would it be possible to to use a *.inc file with this? If I have a REALLY long long list of functions or my website gets a ton of hits, would include() slow anything down or be inefficient in any way?
    "There is no spoone" -The Matricks

  5. #4
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    You can use either. The PHP manual just says the level of error reporting is different.

    There won't be a significant server impact, it'll be just like you had all your functions in the main page anyway.

    Just make sure you put the PHP tags in the included file, otherwise they'll all show up as text. You can include a *.inc file too, but for added security you can save it as a PHP file, and use a definition to stop the functions being accessed remotely.

    Tutorial for that here: http://www.biorust.com/tutorials/detail/214/en/

    I myself include my functions, but have a separate file for each one. Makes it easier for me to edit.

  6. #5
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Quote Originally Posted by spasm attack
    is there a difference between requiring and including? Would it be possible to to use a *.inc file with this? If I have a REALLY long long list of functions or my website gets a ton of hits, would include() slow anything down or be inefficient in any way?
    It's almost exactly the same as doing a #include in C/C++, only because there's no preprocessor compiler, it's more dynamic. The performance impact is virtually 0. I believe PHP does almost the same thing as a C/C++ preprocessor by just substituting file data in place of the include()/require() directive.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Quote Originally Posted by spasm attack
    is there a difference between requiring and including?
    Yes. Including includes the file and tosses a warning if it can't find it. Requiring kills the script if the file wasn't found or couldn't be included for some reason.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:55 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com