Consider a static class (private constructor, only static methods & variables).
Now the rough class definition would look like this:
class A{
private function __construct(){}
public static test(){};
}
class B{
private function __construct(){}
}
Is it somehow possible to call something like B::A::test()
?
Or maybe through a variable? Something like B::$A::test()
?
I guess it is possible by some general call catching, but I can't figure it out...
IMPORTANT: Also, I want to call ANY other static class from B
, not just from the A
class...
EDIT2: What I want to achieve is to call static class through another static class, if possible... very similar to calling a method from object variable - but static class (obviously) is not ment to be instantiated.
EDIT3: Also possible solution is to call it as B::CLASSNAME_METHOD_NAME
and catch it by __callStatic
but I would rather do B::CLASSNAME::METHOD_NAME
...
Another possible solution:
If you don't want to create whole singleton, this could be solution - creating a partial singleton - some kind of singleton-hepler, altough using ->
to call a static method could be confusing!
class AA{
private function __construct(){}
private static $instance;
public function getInstance(){ return empty(self::$instance)?(new self()):self::$instance; }
public function __call($method_name, $args) {
return AA::$method_name($args);
}
public static function test($a, $b){
echo "TEST: A:".$a." B:".$b;
}
}
class B{
private function __construct(){}
public static function A(){
return AA::getInstance();
}
}
B::A()->test("one", "two");