php / php/php-src

Support for nullsafe function call syntax

オープン
#14,547 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue の PHP スニペットを使って報告された動作を再現し、その後、nullsafe operator に関するリンク先の RFC と、nullsafe 呼び出しに関する既存の実装およびテストを確認してください。$g?() の意図された扱いを特定して実装し、通常の呼び出しに対して文書化されたエラーを維持し、期待される動作に一致させれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。