XF 2.3 Bizarre error since upgrading to PHP 8.3.9...

Jaxel

Well-known member
In one of my addons, I am getting the following error:

ParseError: syntax error, unexpected token "match", expecting identifier in src/addons/EWR/Torneo/Repository/Match.php at line 8
  1. Composer\Autoload\{closure}() in src/vendor/composer/ClassLoader.php at line 427
  2. Composer\Autoload\ClassLoader->loadClass()
  3. spl_autoload_call() in src/XF.php at line 406
  4. XF::createAliasForClass()
  5. class_exists() in src/XF/Mvc/Entity/Manager.php at line 296
  6. XF\Mvc\Entity\Manager->getRepository() in src/XF/Mvc/Entity/Repository.php at line 57
  7. XF\Mvc\Entity\Repository->repository() in src/addons/EWR/Torneo/Repository/League.php at line 85
  8. EWR\Torneo\Repository\League->prepareViewParams() in src/addons/EWR/Torneo/Pub/Controller/League.php at line 173
  9. EWR\Torneo\Pub\Controller\League->actionLeague() in src/XF/Mvc/Dispatcher.php at line 362
  10. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
  11. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  12. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  13. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2777
  14. XF\App->run() in src/XF.php at line 798
  15. XF::runApp() in index.php at line 23
Here is my code:

src/addons/EWR/Torneo/Repository/League.php:85
Code:
        $mEntries = $this->repository('EWR\Torneo:Match')->findMatch()->limit($perSide);

src/addons/EWR/Torneo/Repository/Match.php
Code:
<?php

namespace EWR\Torneo\Repository;

use XF\Mvc\Entity\AbstractCollection;
use XF\Mvc\Entity\Repository;

class Match extends Repository
{
    public function findMatch()
    {
        return $this->finder('EWR\Torneo:Match')
            ->with('Event', true)
            ->with('PlayerOne')
            ->with('PlayerOne.User')
            ->with('PlayerTwo')
            ->with('PlayerTwo.User');
    }
}

What would be causing this error? I have similar finder functions running perfectly fine.
 
Try changing the class name from Match to something else, such as TournamentMatch or any other name that doesn't conflict with reserved keywords.
 
Changing the class name to MatchR brings around a new error:

ParseError: syntax error, unexpected token "match", expecting identifier in src/addons/EWR/Torneo/Entity/Match.php at line 7
  1. Composer\Autoload\{closure}() in src/vendor/composer/ClassLoader.php at line 427
  2. Composer\Autoload\ClassLoader->loadClass()
  3. class_exists() in src/XF/Mvc/Entity/Manager.php at line 52
  4. XF\Mvc\Entity\Manager->getEntityClassName() in src/XF/Mvc/Entity/Manager.php at line 71
  5. XF\Mvc\Entity\Manager->getEntityStructure() in src/XF/Mvc/Entity/Manager.php at line 260
  6. XF\Mvc\Entity\Manager->getFinder() in src/XF/Mvc/Entity/Repository.php at line 45
  7. XF\Mvc\Entity\Repository->finder() in src/addons/EWR/Torneo/Repository/MatchR.php at line 12
  8. EWR\Torneo\Repository\MatchR->findMatchR() in src/addons/EWR/Torneo/Repository/League.php at line 85
  9. EWR\Torneo\Repository\League->prepareViewParams() in src/addons/EWR/Torneo/Pub/Controller/League.php at line 173
  10. EWR\Torneo\Pub\Controller\League->actionLeague() in src/XF/Mvc/Dispatcher.php at line 362
  11. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
  12. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  13. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  14. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2777
  15. XF\App->run() in src/XF.php at line 798
  16. XF::runApp() in index.php at line 23
It seems I have to rename the entire entity?
 
Yes, you need to rename the entity class as well to avoid using the reserved keyword match. Anywhere else the Match entity is referenced.
 
Back
Top Bottom