Jump to content

Class object is NULL although class has been constructed


AD1ctive

Recommended Posts

Hello everyone!

 

I'm coding my own little cms at the moment and got a problem. First, however, I'll explain how it works:

 

Theres one main class called CMS which initiates all the sub classes when constructed. Then CMS can be used to access other classes. This is an example Code:

 

class CMS {
    public static $PAGE;


    // PUBLIC FUNCTION: __construct()
    // initiates the whole Yeha system
    //
    public function __construct() {
        $this->initPagePlugin();
    }


    // PROTECTED FUNCTION: initPagePlugin()
    // sets object self::$PAGE if not set yet
    //
    protected function initPagePlugin() {
        if(!isset(self::$PAGE)) self::$PAGE = new PagePlugin();
    }


    // STATIC FUNCTION: PAGE()
    // sets object self::$PAGE if not set yet and returns it
    //
    public static function PAGE() {
        //if(!isset(self::$PAGE)) self::initPagePlugin();
        return self::$PAGE;
    }
}

 

Later own all the functions of the class PagePlugin can be called using the command:

 

CMS::PAGE()->exampleFunction();

 

This way works fine with all the sub classes, e.g. Database, Template, etc but not with the one above: "PagePlugin". For some reason PagePlugin is being constructed but not the object $PAGE. Consequently, I can't call PagePlugin's functions later on.

 

Have u got an idea what's wrong?

 

Thanks for your help ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.