0

Say I have a base object, CacheObject:

abstract class CacheObject {
    protected static $handler = null;

    public static function setCacheHandler($handler) {
        static::$handler = $handler;
    }

    public static function getCacheHandler($handler) {
        return static::$handler;
    }
}

class A extends CacheObject {

}

class B extends CacheObject {

}

A::setCacheHandler('test');
var_dump(B::getCacheHandler());

B will give me "test", which I believe is because class A does not have it's own defined property $handler... so it is using the inherited one, shared by class B. Is this accurate?

Is there any way I can in fact have them set separately, without needing to declare $handler within every object?

Kaitlyn2004
  • 3,879
  • 4
  • 16
  • 16

1 Answers1

0

Your

public static function getCacheHandler($handler) { // No need to pass arg here
        return static::$handler;
    }

should be

public static function getCacheHandler() {
        return static::$handler;
    }
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126