php / php/php-src

Support for nullsafe function call syntax

未关闭
#14,547 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Feature Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

The following code:

<?php
class Foo {
    public function __invoke(): string {
        return 'foo invoked';
    }
}

$f = new Foo();
var_Dump($f());

results in this expected output:

string(11) "foo invoked"
$g = null;
$g();

results in this expected output

Fatal error: Uncaught Error: Value of type null is not callable
$g = null;
$g?->__invoke();

results in this expected output:

string(11) "foo invoked"

As the call to ->__invoke() can be shortened to () I would have expected to be able to use the nullsafe operator here as well and write

$g = null;
$g?();

But this results in in this output:

Parse error: syntax error, unexpected token ")"

I would have expected

string(11) "foo invoked"

Is this on purpose? I could not find any mention of invoke in the RFC. So was this overseen?

See also https://3v4l.org/n09i2

PHP Version

All currently supported PHP-Versions

Operating System

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 issue 中的 PHP 代码片段重现所报告的行为,然后阅读链接的 nullsafe operator RFC,以及现有的 nullsafe 调用实现和测试。完成的标准是确定并实现对 $g?() 的预期处理,同时保留普通调用的已记录错误,并符合预期行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。