Question: I am learning OOP and very confuse to use classes for each other.

I am having total 3 classes

```
//CMS System class
class cont_output extends cont_stacks
{
    //all methods to render the output
}

//CMS System class
class process
{
    //all process with system and db
}

// My own class to extends the system like plugin
class template_functions
{
    //here I am using all template functions
    //where some of used db query
}

```

Now I want to use my own class template\_functions withing both system classes. But very confused how to use it. Please help me to understand this.

**EDIT:
I am sorry champs I forgot to mention that my own class in different PHP file.**

Answer: 
First, make sure, that you `include` the class file before using it:

```
include_once 'path/to/tpl_functions.php';

```

This should be done either in your index.php or on top of the class which uses `tpl_function`. Also note the possibility of [`autoloading`](http://www.php.net/manual/en/language.oop5.autoload.php) classes:

Since PHP5 you have to possibility to autoload classes. This means you register a hook function that is been called everytime when you try to use a class which's code file hasn't been included yet. Doing it you won't need to have `include_once` statements in every class file. Here comes an example:

*index.php* or whatever application entry point:

```
spl_autoload_register('autoloader');

function autoloader($classname) {
    include_once 'path/to/class.files/' . $classname . '.php';
}

```

From now on you can access the classes without to worry about including the code files anymore. Try it:

```
$process = new process();

```

---

Knowing this, there are several ways how you can use the `template_functions` class

---

Just *use it*:

You can access the class in any part of the code if you create an instance of it:

```
class process
{
    //all process with system and db

    public function doSomethging() {
        // create instance and use it
        $tplFunctions = new template_functions();
        $tplFunctions->doSomethingElse();
    }
}

```

Instance members:

Take the process class for example. To make the template\_functions available inside the `process` class, you create an instance member and initialize it somewhere, where you need it, the constructor seems to be a good place:

```
//CMS System class
class process
{
    //all process with system and db

    // declare instance var
    protected tplFunctions;

    public function __construct() {
        $this->tplFunctions = new template_functions;
    }

    // use the member : 

    public function doSomething() {
        $this->tplFunctions->doSomething();
    }

    public function doSomethingElse() {
        $this->tplFunctions->doSomethingElse();
    }
}

```
You can extend the `template_functions` class, then you can use all the functions.

```
class cont_output extends cont_stacks //cont_stacks has to extend template_functions
{
    public function test() {
        $this->render();
    }
}

class process extends template_functions
{ 
    public function test() {
        $this->render();
    }
}

class template_functions
{
    public function render() {
        echo "Works!";
    }
}

```