Question: I'm trying to create simple function that can be executed on **any page**.

```
function something() {
    $string = 'Hello World'; 
    return $string;
}

```

Let's say I'm in the category page, I would just call `$a = something();` and it would return my value

Platform : OpenCart

*P.S. I'm still studying MVC architecture*

Answer: 
Create a new file to system/library/yourclassname.php with same code.

Also please add a class name to your function as below:

```
class yourclassname {

  function something() {
    $string = 'Hello World'; 
    return $string;
  }
}

```

And add it to your index.php file as below;

```
$registry->set('yourclassname', new yourclassname($registry));

```

Finally add it to your startup.php file as below:

```
require_once(DIR_SYSTEM . 'library/yourclassname.php');

```

You can use it anywhere with $this->yourclassname->something();

Thats All..
Matricore's answer worked perfectly for me, but I also had to construct the new class with the config and db available.

Code below:

```
class yourclassname {

    public function __construct($registry) {
        $this->config = $registry->get('config');
        $this->db = $registry->get('db');
    }

}

```

You can then run queries via $this->db->query("Your query here");