Function Include?

  • Moses08
  • Graduate
  • Graduate
  • Moses08
  • Posts: 196

Post 3+ Months Ago

Hi,

I'm working on a rather large PHP script. I need to create a large number of functions for this script. Is it best to create a file with all the functions in it and then use includes to call it into everypage, or is there a better way?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Depends on the nature of the script

If you need every function every time then just have it as one file. There is no need for includes, other than for organisation of code.

If you need a group of functions one time the script is called and a different group another time, then group them as they would be needed and include just the function groups that you need.
  • Moses08
  • Graduate
  • Graduate
  • Moses08
  • Posts: 196

Post 3+ Months Ago

OK, thx. I'm just worried about the script getting too large and loading very slowly.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

well thats why you only load what you need. If you have to load everything at some point or another then you might as well do it all at once. TBH it probably won't take long to load at all, concentrate on making the script execute as quickly as possible.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Try to create your functions in the form of classes with public properties you can set. Trust me when I say that the functions you create now you will use again!

I must have built the same wheel at least five times before realising this.

Include files don't really take all that long to load. I have, at stages, loaded ten to fifteen files without any dramatic side effects. Like RTM says, try making the scripts execute as quickly as possible with effecient code.

The files don't have to to bee downloaded to the client like javascript files, so file size is also not to importtant -just don't go over board
  • Moses08
  • Graduate
  • Graduate
  • Moses08
  • Posts: 196

Post 3+ Months Ago

I have decided on a setup that has:

1. index.php - main file, lots of forms.
2. whatever.php - different forms access different pages that process the forms, includes index.php
3. variables.php - stores all my variable declaration, included in every page.

Will this setup be good?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

i would use a request rather than include it will make your page load alot fast if your functions page is big ^^

PHP Code: [ Select ]
 
<?
 
request("functions.php");
 
?>
 
 
  1.  
  2. <?
  3.  
  4. request("functions.php");
  5.  
  6. ?>
  7.  
  8.  
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

what's request do spoof (or anyone else)? I checked the manual but it's not there :?

http://uk.php.net/manual-lookup.php?pattern=request
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

its like include but it only gathers the information you ask for such as a function, or a varible.

this alues you to make a 5000 line functions page and only incert 20 lines worth into your page that is being displayed
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

I think it is require not request Spoof is talking about. But I don't know anything about 5000 to 20 ratio. Can you please refer me to some documentation on this function, please Spoof?
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Yeah, It throws an undefined error for me if I change include to request, which does make me wonder. Google comes up with nothing on the first two pages and the manual says it doesn't exist. I'm not having a go spoof, but I cannot find anything to suggest it exists :?

And if it is require, as quantumcloud suggests, the PHP documentation says this:
Quote:
The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Be warned that parse error in required file doesn't cause processing halting.


From this page here:

http://www.php.net/manual/en/function.include.php
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

ya so i cant sleep or keep track of whats what but hey thats why they have the text doc! ^^ but it does do something like that makes it so your page loads fast

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 97 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.