为什么这会在 PHP 7.2 而不是 PHP 7.4.5 上给我一个语法错误?

Why is this giving me a syntax error on PHP 7.2 but not PHP 7.4.5?

我只是想确保我不会在制作过程中遇到任何令人讨厌的意外。下面的代码块导致语法错误,意外的 ')' 在生产服务器上 PHP 7.2.34 但在本地 (PHP 7.4.5).

错误就在 upload() 的最后一个参数之后

    // array
    $file_ids = $this->common->upload(
        $folder_id, 
        $filenames, 
        (int) $invoice->projectid, 
        ['file_attach'], // unexpected ')'
    );

不得不将其更改为此,现在可以使用了。


$proj_id = intval($invoice->projectid);     

// array
$file_ids = $this->common->upload($folder_id, $filenames, $proj_id, ['file_attach']);

PHP 7.3 首次允许在函数调用中使用尾随逗号。所以 7.2 会导致错误,但 7.4 不会。

https://wiki.php.net/rfc/trailing-comma-function-calls

https://laravel-news.com/php-trailing-commas-functions