0

I'm building a framework. I have a problem loading in multiple controllers, because they extend a base controller, where the instances are changed to the last loaded controllers options. How can i affect only the extended base controller of the controller class, that I'm currently working in, instead of affecting all instances of the base controller?

class loader
{
    private static $_inst;

    public function __construct($class) 
    {
        self::$_inst = $class;
    }
}

abstract class base_controller 
{
    protected $load;

    public function __construct() 
    {
        $this->load = new loader($this);
    }
}

class controller1 extends base_controller {}

class controller2 extends base_controller {}

When the first controller loads, it sets the instance in the loader. But when you load the second controller, it sets controller1's loader objects static $_inst to controller2's instance. Suggestions?

2
  • You are trying to dereference a null pointer at line 525. Commented Mar 4, 2014 at 12:04
  • Do you use static properties in your base class? Commented Mar 4, 2014 at 12:06

2 Answers 2

1

$_inst will stay the same in all classes because you have defined it as static

Solution:

Just remove static and make it private $_inst;

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is, that if I remove static, it will make a recursion (loop), but thanks.
1

Static members are shared at the level of its declaration class. If you want an other comportment, you have to declare it in every children classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.