Skip to content

MissUsingParentKeyword ​

info on by default quick-fix

Group: Code style · PhpStorm name: MissUsingParentKeywordInspection

parent::m() is meant for calling the overridden implementation of the current method. When it calls some other inherited method that nobody in the hierarchy overrides, it is equivalent to $this->m() / self::m(), and using parent:: there only misleads readers (and silently bypasses future overrides).

Example ​

php
<?php

class Widget
{
    public function paint($color) {}
    public static function registry() {}
    public function resize() {}
    public function layout() {}
}

class Button extends Widget
{
    public function layout()
    {
        parent::layout();
        parent::paint("red", 2);
        parent::registry();
        parent::resize();
        parent::missing();
        $fn = function () { parent::paint('x'); };
    }

    public static function build()
    {
        parent::paint('blue');
    }
}

class IconButton extends Button
{
    public function resize() {}
}
php
<?php

class Widget
{
    public function paint($color) {}
    public static function registry() {}
    public function resize() {}
    public function layout() {}
}

class Button extends Widget
{
    public function layout()
    {
        parent::layout();
        $this->paint("red", 2);
        self::registry();
        parent::resize();
        parent::missing();
        $fn = function () { parent::paint('x'); };
    }

    public static function build()
    {
        parent::paint('blue');
    }
}

class IconButton extends Button
{
    public function resize() {}
}

Reported:

  • line 16: Call it as '$this->paint("red", 2)' instead of through 'parent::'.
  • line 17: Call it as 'self::registry()' instead of through 'parent::'.

Options ​

OptionTypeDefaultEffect

Configure ​

In custos.json:

json
{
  "rules": {
    "MissUsingParentKeyword": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore MissUsingParentKeyword

/**
 * @noinspection MissUsingParentKeywordInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.