PHPMD避免静态访问父级

Ben*_*Ben 1 php oop static code-cleanup phpmd

有没有办法避免parent::PHP类中的静态访问器,或者这是一个使用时间@SuppressWarnings(StaticAccess)

同样,似乎这个StaticAccess警告在可疑的地方突然出现.例如,异常处理 - 当我throw new Exception(...),PHPMD抱怨静态访问时.但是......没有其他方法可以做到(我已经发现)所以我有更多的警告抑制器比我想要的更多.这是正常的吗?

编辑

根据要求,这是一个例子 - 它非常简单:

class aaa {
    private $someReasonForAnException = true;

    public function __construct() {
        echo 'AAA<br>';
        if ($this->someReasonForAnException) {
            throw new Exception("Something happened that's worth noticing!");
        }
    }
}

class bbb extends aaa {    
    public function __construct() {
        echo 'BBB<br>';
        parent::__construct();
    }
}

$BBB = new bbb();
Run Code Online (Sandbox Code Playgroud)

PHPMD将报告上述两个错误:StaticAccess错误Exception,以及调用StaticAccess错误parent::__construct().

为了避免这种情况,我必须注意两个类@SuppressWarnings,这看起来很笨,并且也不会显示"真正的"静态访问问题.

Dan*_*ell 5

一个简单而可持续的解决方案可能是