在类属性中扩展类?

Suppose that I've this class:

class Loader 
{
     function library($name)
     {
          require $name . '.php';
     }
}

and now I include the class foo ($name) inside my controller, like this:

class Controller
{
    function __construct()
    {
         $this->load = new Loader();
    }
}

class Child_Controller extends Controller
{
    function __construct()
    {
         parent::__construct();
         $this->load->library('foo'); 
         init();
    }
}

is possible, for example, access to the included class inside $this? Like:

class Child_Controller extends Controller
{
    //..construct above..

    function init()
    {
        $this->print('some text');
    }
}

where print is a method of foo, the class included:

class Foo
{
    function print($message)
    {
         echo "your message: " . $message;
    }
}

So, summing, I want include in the child controller, in $this, all the method of the included class by the Loader class extended by the base controller. Is this possible?

Or another idea would be create dynamically in the Child_Controller, a property that take the name of the included class, so, for call the method of foo I can do something like:

$this->Foo->print('some text');

No, you can't do that however you can do something similar in storing Foo in a generic property like this:

class Child_Controller 
{
    private $lib;

    function __construct()
    {
        parent::__construct();
        $this->lib = $this->load->library('Foo');
        $this->init();
    }

    function init()
    {
        $this->lib->print('Hello World!');
    }
}

If you want to instantiate multiple libraries then rather than using a dynamic name for the variable you should use an array with the library name as the key, like this:

class Child_Controller 
{
    private $libs = [];

    function __construct()
    {
        parent::__construct();
        $this->libs['Foo'] = $this->load->library('Foo');
        $this->init();
    }

    function init()
    {
        $this->libs['Foo']->print('Hello World!');
    }
}

If you can't use an array and absolutely must use a variable name you can do that like this:

class Child_Controller 
{
    function __construct()
    {
        $var = 'Foo';
        $this->{$var} = $this->load->library($var);
        $this->init();
    }

    function init()
    {
        $this->Foo('Hello World!');
    }
}