Files:scan command only works if setting NC_loglevel env var

Hi,
While troubleshooting an (apparently successful) upgrade to 23 I am facing a weird behavior.

The files:scan command function properly when I set the NC_loglevel environment variable but fails with the following error if I don’t:

If I’m executing sudo -u nextcloud NC_loglevel=x php /usr/share/webapps/nextcloud/occ files:scan --all instead, the command scans the files correctly.

Here are the details of my NextCloud installation.

$ sudo -u nextcloud php /usr/share/webapps/nextcloud/occ status
  - installed: true
  - version: 23.0.2.1
  - versionstring: 23.0.2
  - edition:
  - maintenance: false
  - needsDbUpgrade: false
  - productname: Nextcloud
  - extendedSupport: false

$ php -v
PHP 8.1.3 (cli) (built: Feb 16 2022 13:27:56) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies
[foo@bar nextcloud]$ sudo -u nextcloud php /usr/share/webapps/nextcloud/occ files:scan --all
Starting scan for user 1 out of 7 (foobar)
PHP Fatal error:  During inheritance of JsonSerializable: Uncaught ErrorException: Return type of OCA\Deck\Db\RelationalEntity::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/webapps/nextcloud/apps/deck/lib/Db/RelationalEntity.php:66
Stack trace:
#0 /usr/share/webapps/nextcloud/apps/deck/lib/Db/RelationalEntity.php(28): OCA\Files\Command\Scan->exceptionErrorHandler(8192, 'Return type of ...', '/usr/share/weba...', 66)
#1 /usr/share/webapps/nextcloud/lib/composer/composer/ClassLoader.php(571): include('/usr/share/weba...')
#2 /usr/share/webapps/nextcloud/lib/composer/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/usr/share/weba...')
#3 /usr/share/webapps/nextcloud/apps/deck/lib/Db/Acl.php(26): Composer\Autoload\ClassLoader->loadClass('OCA\\Deck\\Db\\Rel...')
#4 /usr/share/webapps/nextcloud/lib/composer/composer/ClassLoader.php(571): include('/usr/share/weba...')
#5 /usr/share/webapps/nextcloud/lib/composer/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/usr/share/weba...')
#6 /usr/share/webapps/nextcloud/apps/deck/lib/Db/BoardMapper.php(190): Composer\Autoload\ClassLoader->loadClass('OCA\\Deck\\Db\\Acl')
#7 /usr/share/webapps/nextcloud/apps/deck/lib/Db/BoardMapper.php(117): OCA\Deck\Db\BoardMapper->findAllByUser('foobar', NULL, NULL, NULL, true, NULL, NULL)
#8 /usr/share/webapps/nextcloud/apps/deck/lib/Sharing/DeckShareProvider.php(698): OCA\Deck\Db\BoardMapper->findAllForUser('foobar')
#9 /usr/share/webapps/nextcloud/lib/private/Share20/Manager.php(1375): OCA\Deck\Sharing\DeckShareProvider->getSharedWith('foobar', 12, NULL, -1, 0)
#10 /usr/share/webapps/nextcloud/apps/files_sharing/lib/MountProvider.php(92): OC\Share20\Manager->getSharedWith('foobar', 12, NULL, -1)
#11 /usr/share/webapps/nextcloud/lib/private/Files/Config/MountProviderCollection.php(118): OCA\Files_Sharing\MountProvider->getMountsForUser(Object(OC\User\User), Object(OC\Files\Storage\StorageFactory))
#12 /usr/share/webapps/nextcloud/lib/private/Files/Filesystem.php(429): OC\Files\Config\MountProviderCollection->addMountForUser(Object(OC\User\User), Object(OC\Files\Mount\Manager))
#13 /usr/share/webapps/nextcloud/lib/private/Files/Filesystem.php(354): OC\Files\Filesystem::initMountPoints('foobar')
#14 /usr/share/webapps/nextcloud/lib/private/legacy/OC_Util.php(326): OC\Files\Filesystem::init('foobar', '/foobar/files')
#15 /usr/share/webapps/nextcloud/lib/private/Files/Utils/Scanner.php(115): OC_Util::setupFS('foobar')
#16 /usr/share/webapps/nextcloud/lib/private/Files/Utils/Scanner.php(200): OC\Files\Utils\Scanner->getMounts('/foobar')
#17 /usr/share/webapps/nextcloud/apps/files/lib/Command/Scan.php(143): OC\Files\Utils\Scanner->scan('/foobar', true, NULL)
#18 /usr/share/webapps/nextcloud/apps/files/lib/Command/Scan.php(199): OCA\Files\Command\Scan->scanFiles('foobar', '/foobar', Object(Symfony\Component\Console\Output\ConsoleOutput), false, true, false)
#19 /usr/share/webapps/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /usr/share/webapps/nextcloud/core/Command/Base.php(168): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php(1009): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /usr/share/webapps/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /usr/share/webapps/nextcloud/console.php(99): OC\Console\Application->run()
#26 /usr/share/webapps/nextcloud/occ(11): require_once('/usr/share/weba...')
#27 {main} in /usr/share/webapps/nextcloud/apps/deck/lib/Db/RelationalEntity.php on line 28