Well... there's your problem. Moodle doesn't (yet) support PHP 8
Moodle 4 now works with php8.0 but I've just had this issue today.
I realised cron was not working. I ran cron.php from the command line and got the error.
Checked phpinfo - definitely version 8.0
Then realised it is possible to have a different version of php running on the command line than under Apache.
The command line version was 8.1
Changed it to 8.0 and cron now works.
We get this a LOT. Everybody assumes that command line PHP and the "web" version will be the same but they don't have to be.
Also... *core* Moodle is now compatible with PHP 8. That doesn't mean that any optional plugins will be.
Also... *core* Moodle is now compatible with PHP 8. That doesn't mean that any optional plugins will be.