php {inheritdoc}的需求是什么?

l7wslrjt  于 2023-06-21  发布在  PHP
关注(0)|答案(2)|浏览(101)

我经常与Drupal和类打交道,有时我会读到这样的东西:

/**
  * {@inheritdoc}
  */

  // return the form definition
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('hello_world.custom_salutation');

    $form['salutation'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Salutation'),
      '#description' => $this->t('Si prega di inserire il saluto che si desidera usare'),
      '#default_value' => $config->get('salutation'),
    );

InheritDoc是什么意思?

vfh0ocws

vfh0ocws1#

这是一个 docblock 语法,是Drupal的API documentation and comment standards的一部分:
您可以在类中使用{@inheritdoc}
如果你正在重写或实现一个基类或接口的方法,并且文档应该与基类/接口方法完全相同
它还声明 * 必须是docblock中的唯一一行。

brccelvz

brccelvz2#

2023年起停止使用{@inheritdoc}

在今天(2023年以后),在docblocks中使用{@inheritdoc}可能是多余的,因为工具已经发展并且能够独立地确定继承。
Drupal 8最大的依赖是Symfony。Symfony 6.2删除了{@inheritdoc}(阅读:https://github.com/symfony/symfony/pull/47390),其依据是:
看起来这个PHP文档是无用的。IDE能够继承文档(至少VS Code和PHP Storm)。而像PHP Stan这样的工具也能够
Drupal开发人员阅读以下内容:https://www.drupal.org/project/coding_standards/issues/3335320

相关问题