Yesideez Posted February 25, 2007 Share Posted February 25, 2007 Just added a timer to the pages on my website so I know how long it takes for pages to load and it made me think of this question... I have a collection of PHP functions, some are used in many scripts, some are only used in a few. At the moment they total around 15KB and there's no doubt this number will grow. I do my best to optimise as much as possible as often as possible and was wondering whether it makes sense to place them all into one file and use require_once or whether they're best left as single files and have a few require_once calls in each script? Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/ Share on other sites More sharing options...
Daniel0 Posted February 25, 2007 Share Posted February 25, 2007 I'd place them in one file if that were the only options. But if I did this myself I would store them in classes categorizing the functions, each with their own file. For instance a timer class, a cookie handling class, a session handling class etc. Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193856 Share on other sites More sharing options...
Yesideez Posted February 26, 2007 Author Share Posted February 26, 2007 Thanks, I've never used classes. Do you have a link where I could read up on them please? Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193937 Share on other sites More sharing options...
Yesideez Posted February 26, 2007 Author Share Posted February 26, 2007 Just found the classes tutorial on here Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193941 Share on other sites More sharing options...
magnetica Posted February 26, 2007 Share Posted February 26, 2007 Your best bet is to just Google it But as a starter: <?php class AboutNumbers //with a few functions for numbers inside { var $var1; var $var2; function set_numbers($number1, $number2) { $this->var1 = $number1; $this->var2 = $number2; } function add_numbers() { return ($this->var1 + $this->var2); } } class AboutNumbers //with a few functions of strings inside { $str1 = "Hello"; $str2 = " World"; function concat_strings() { $newstring = $str1 . " out there " . $str2; } } ?> Basically classes are a way of just catergorises your functions Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193945 Share on other sites More sharing options...
Yesideez Posted February 26, 2007 Author Share Posted February 26, 2007 Yeah but it's how they're set up, stored, activated and used that I've no idea about. It's just gone midnight here so I'll be off to bed in about 45 minutes which is when this programme ends. Good job I don't start work tomorrow until 2pm! Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193948 Share on other sites More sharing options...
magnetica Posted February 26, 2007 Share Posted February 26, 2007 Where you at? The UK. I'm in England Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193949 Share on other sites More sharing options...
Yesideez Posted February 26, 2007 Author Share Posted February 26, 2007 Yeah - Ottery St Mary in Devon btw, just adapted the main index.php on my website for classes, made a class and it works!!! I'm so happy right now I'm tempted to stay up longer and code some more but I mustn't get started on something new as it's far too late. Don't want to get out of bed at 1pm tomorrow like I have been! Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193955 Share on other sites More sharing options...
magnetica Posted February 26, 2007 Share Posted February 26, 2007 Yea thats what I do. Stay up too late and get up too late. Btw your only 50miles from me. I'm in Saltash about 5 miles from Plymouth in Devon Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193959 Share on other sites More sharing options...
Yesideez Posted February 26, 2007 Author Share Posted February 26, 2007 About 70 miles. 10 from here to Exeter, then 54 to Plymouth then about 5 more but I think I could be wrong with that 5... I've got family in Plymouth and my fiance has family in Saltash - small world! Did you get my PM? Quote Link to comment https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/#findComment-193960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.