Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/40078-solved-functions-storing-and-using/
Share on other sites

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.

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

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!

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!

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.