Guide  Fixing "Declaration of ... must be compatible with ..." errors between two XenForo add-ons

Gwendal

Developer
Moderator
Customer
Verified license
18 products BoardGameHub Classified Drafts Emporium Emporium Client GameHub GroupFlair Immersive Messenger Journey Level Plans Teams Watch Party XenCard XenPing XenSpotlight XenStaff XenStreak
This fatal error usually appears right after you install or update an add-on, and it can break a whole feature for everyone: posting a reply, starting a direct message, saving a profile. Members just see "Oops! We ran into some problems". The server error log shows something like:

Code:
Fatal Error: Declaration of AddOnB\XF\Service\Something::method(XF\Entity\User $user) must be compatible with AddOnA\XF\Service\Something::method($user)

The good news: it is never your configuration, and it is quick to get out of.

Why it happens​

XenForo add-ons customise core classes through class extensions. When two add-ons extend the same XenForo class, XenForo chains them: the second add-on's class extends the first one's, which extends XenForo's own class.

PHP has strict rules for a method that is redefined down such a chain: the parameters must stay compatible with the parent. If the first add-on in the chain wrote the method without the types XenForo uses ($user instead of User $user), and the second add-on copied XenForo's exact signature, PHP refuses to load the second class. Each add-on works on its own; only the combination fails, which is why neither developer saw it on their test board.

Read the message in the right order​

  • The first class named ("Declaration of AddOnB\...") is the one PHP refused to load.
  • The second class named ("must be compatible with AddOnA\...") is its parent in the chain.
  • Open XenForo's own class (the part after XF\ in the path, under src/XF/) and compare: the add-on whose signature differs from XenForo's is the one that needs fixing. In our experience it is the one with the looser signature, missing types or a missing return type.

Get your board working again now​

  1. In Admin CP > Add-ons, disable one of the two add-ons. Pick the one you can live without for a day; disabling keeps all its data.
  2. If the Admin CP itself fails to load, use the command line from your board root:
    Code:
    php cmd.php xf:addon-disable Vendor/AddOnId
  3. Test the action that failed (reply, start a direct message, and so on).

Fix it for good​

  • Check both add-ons for updates first: this kind of conflict is usually fixed quickly once reported.
  • Report it to the developer of the add-on whose signature differs from XenForo's, with the full error line and the names and versions of both add-ons. Mention the other add-on: they need it to reproduce.
  • Do not edit the add-on's PHP files yourself unless you know exactly what you are doing: your change disappears at the next update, and the file health check will flag it.
  • Once the fixed version is installed, enable the add-on you disabled and test again.

A real example from our tickets​

A customer could no longer start any direct message: Immersive Messenger and SV Warning Improvements both extend XenForo's conversation notifier, and Messenger declared one method without XenForo's types. Messenger 2.6.5 fixed it by copying XenForo's exact signatures, and every release since is checked automatically against XenForo's own classes before it ships. Store page: Immersive Messenger.

Seeing this error with one of our add-ons? Open a ticket in Support tickets with the log entry and the list of add-ons you run, and I will look at it straight away.
 
Ready to make your forum unforgettable?Browse the storeSee the plans