简体   繁体   中英

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

I just want to make sure I don't get any nasty surprises on production. This block of code below caused a syntax error, unexpected ')' on production server with PHP 7.2.34 but not on local (PHP 7.4.5).

The error is right after the last argument of upload()

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

Had to change it to this and now it works.


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

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

PHP 7.3 allowed trailing commas in function calls for the first time. So 7.2 would cause an error, but 7.4 wouldn't.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM