douyun1860 2019-03-14 09:22
浏览 158
已采纳

为什么PhpStorm允许使用yield函数的null返回类型?

I used PhpStorm to auto add the return type in the function below:

/**
 * @return \Generator|null
 */
function yieldTest(): ?\Generator
{
    yield from [1, 2, 3];
}

My question: Why does it add the null option alongside \Generator?

I can't see a way for this to return null so I'm wondering if I'm overlooking something in the way yield works or if this is a quirk from PhpStorm's side and can safely be ditched?

Update:

To clarify - I am asking why PHPStorm generated the return type as ?\Generator.

I understand that it then added null to the php doc @return tag because on the ?.

Update 2:

Here is the full code form a test file before generating extra bits:

class yieldTestClass
{
    public function yieldTest()
    {
        yield from [1, 2, 3];
    }
}

And here is the code after choosing "Declare the return type" from the context menu on the method name:

class yieldTestClass
{
    public function yieldTest(): ?\Generator
    {
        yield from [1, 2, 3];
    }
}

I am not sure if this is a native feature in the IDE or from a plugin but if it is a plugin I am guessing it would be this https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended-

Same question either way though.

  • 写回答

2条回答 默认 最新

  • dongliping003116 2019-03-14 11:12
    关注

    That inspection and intended fix (the code added) is provided by a Php Inspections (EA Extended) plugin.

    Please report to a plugin author: https://github.com/kalessil/phpinspectionsea/issues

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果