I'm writing a "semi-mixin system" for PHP 5.3 (traits are not available). The way this is typically done is by using the magic __call method. I was looking for a way to tell PhpStorm my class implements an interface/other class. I noticed code completion suggest an "@is" doc tag, but is doesn't seem to do anything.
I tried to use it something like this:
<?php
/**
* @is MixinA
* @is MixinB
*/
class MyClass {
private $a;
private $b;
public function __construct() {
$this->a = new MixinA();
$this->b = new MixinB();
}
public function __call($name, $args) {
$callObject = null;
if (is_callable($this->a, $name)) {
$callObject = $this->a;
} elseif (is_callable($this->b, $name)) {
$callObject = $this->b;
}
if ($callObject !== null) {
call_user_func (array($callObject, $name), $args);
}
}
}
class MixinA {
public function methodA() { ... }
public function methodB() { ... }
}
class MixinB {
public function methodC() { ... };
public function methodD() { ... };
}
$object = new MyClass();
$object->methodA();
$object->methodD();
Is there a phpdoc tag to do this, and how do I use it? I know I can use @method and @property, but that's too cumbersome since there a lot of methods.
Thanks in advance.
Hi Wouter,
Unfortunately there is no such tag at all .. and currently no other way except already mentioned @method and @property.
Here is the ticket that asks for such support/implementation in PhpStorm (be it PhpStorm-only supported tag or whatever): http://youtrack.jetbrains.com/issue/WI-1730