Jump to content

[SOLVED] Functions - storing and using


Yesideez

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.