Error in Cron for version 29.0.3

Currently, after an upgrade of nextcloud to version 29.0.3 I am facing the following error:

PHP Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /var/www/[censored]/cron.php on line 187

which is the following part in the cron:

if ($timeSpent > $cronInterval) {
                                $logLevel = match (true) {
                                        $timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,
                                        $timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR,
                                        $timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN,
                                        $timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO,
                                        default => \OCP\ILogger::DEBUG,
                                };
                                $logger->log(
                                        $logLevel,
                                        'Background job ' . $jobDetails . ' ran for ' . $timeSpent . ' seconds',
                                        ['app' => 'cron']
                                );
                        }

to be exact with the following line:
$timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,

Any ideas why this occurs? PHP is Version 8.1 FPM.

The cron job is usually executing using the locally installed PHP version, which has nothing to do with the PHP web (FPM) version. What are the following commands are showing:

which php
php -v

Oh, yeah, you are correct.
Here’s the output:

[18:40:56][root@host:~]$which php
/usr/bin/php
[18:41:41][root@host:~]$php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.4.5, Copyright (c) 2002-2020, by ionCube Ltd.

That’s the point, the match command has first been introduced with PHP 8.0. You should upgrade the PHP command line version or change the code to if ( .. ) { .. } elseif ( .. ) { .. } ... syntax, which should work with all PHP versions.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.