Ryan
Ryan

Reputation: 985

Managing multiple classes from a single class in PHP

I'd like to apologise for the ambiguous title, it's the best one I could think of to define my problem.

I've got a single class in PHP that I want to be invoked from other scripts and I have a few libraries that I want to be able to call functions from, but I want to be able to call those functions from the other libraries via the single class I already have.

class Core
{
// code
}

I want to essentially do the following, Function->Core->Library Function.

The reasoning behind this is that I don't want to have a bunch of classes that get included when the file is run, causing the user to have to remember a bunch of different class names.

This is what I would essentially hope to achieve (but i'm pretty sure this is incorrect syntax) $Core->Data->Get();

Upvotes: 0

Views: 1000

Answers (1)

Jarek.D
Jarek.D

Reputation: 1294

tadaam. That calls for Dependency Injection ;)

class Core
{
    public $lib1;
    public $lib2;
    public function __construct(){
        $this->lib1 = new Lib1Class();
        $this->lib2 = new Lib2Class();
    }



}

Upvotes: 1

Related Questions