I am trying to write class code that can dynamically load external function code
to use as methods of the class. I understand that I could use extends and create
child objects, but it seems there would be a simpler way of going about this.

The point is to limit to bare essentials the amount of code that has to be
used to perform a particular function. And keep all the function code in separate files
that can be required.

```
class _DEMO
{
    public  $_addOn = '';
    public function __construct()
    {
        require_once('DEMOAdd.php');
        $this->addOn = addOn;
    }
}

```

In `DEMOAdd.php`:

```
function addOn($_input)
{
    return 'getting '.$_input;
}

```

How would I load this into the `_DEMO` class? The above produces fatal error.

```
print $_test->addOn('something');

```

In JavaScript it is possible to assign a function to a variable. I realize this
is not JavaScript, but I suspect there is analogous functionality in PHP.

I am also aware of variable variables in PHP but I am having trouble wrapping my brain around that concept.

In response to this advice

When another developer looks at your code it is just not clear what the particular role of this class is. Instead he has to inspect many files and external functions referenced in the class. It just would be better if he could take a look at the class and see "oh, that class does this and that". That's even a central aspect of object oriented programming.

I agree with you on this. I am working on a project that I am the only developer of everything, html, javascript, css,
and php. I have been using class definitions lately, but have written lots of procedural code in the past. The current
project has code that is sectioned off into several class def files so code can be reused in different contexts. My
consideration is if a query from a web page only needs 500 lines of code, why load 1500 lines of code to service the
request. Additionally, this is a cms system with a very limited amount of users (only me at present), so the volume
of traffic is not an issue. But if there was a larger user load, for each user extra code is required, thus the amount
of server memory require increased significantly. The cms web interface is to manage content that direct revision of code
would be very difficult. Yes, I am reinventing the wheel. So has Firestone, General, Nokian, etc etc etc.

Thank you all for the answers

I think I have the answer in anonymous functions that can be assigned to variables, re the php manual

```
$_var = function($_input)
                {
                 return "getting ".$_input;
                }
print $_var('something'); // I have to look back at the manual to varify this line's syntax... yep it looks good.

```