dongmu2174 2019-02-17 22:08 采纳率: 100%
浏览 133
已采纳

在PHP中使用方法后,“:?”是什么意思? [重复]

I just saw this in a Symfony 4 application, and I can't find nowhere what it means

  public function findOneBySomeField($value): ?Article
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }

I know that, now with PHP 7 you can define the expected type of the returned value with ":int $val", but here, what does the ? symbol means ?

</div>
  • 写回答

1条回答 默认 最新

  • duanbin4847 2019-02-17 22:12
    关注

    This is a new feature as of PHP 7.1. See the explanation here

    Type declarations for parameters and return values can now be marked as nullable by prefixing the type name with a question mark. This signifies that as well as the specified type, NULL can be passed as an argument, or returned as a value, respectively.

    This means the expected output of your function will be either an Instance of the class Article or it is NULL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度