In the past month or two I’ve repeatedly seen issues where MODX extras don’t work. They throw a fatal error trying to load a class that is supposed to be available through their autoloader, which exists and is readable.
Having tried to debug several instances of them, it seems to be happening only when multiple composer autoloaders are all loaded simultaneously (i.e. different extras providing their own autoloaders, which may define dependencies and/or PSR0/PSR4 namespace roots). Somewhere along the line, it seems to break the chain and no longer reaches the namespace declaration and just stops processing.
(Wether it’s a good idea to have different extras define their own autoloader… probably not. But we don’t currently have a better way and this has worked fine for years.)
I just don’t have the faintest idea why this is happening. It’s not a dependency conflict as far as I can tell; these are widely different extras with different dependencies and the problem appears trying to load unique classes in their own namespace.
The earliest report I’ve seen is FormIt, from 2018, but I’ve now also seen it in sites with Commerce (and various extensions), Redactor, and MoreGallery. The specific class it fails on is typically the first one being used in a service class constructor, or the service class itself.
It may be a coincidence there’s a bunch of modmore extras in this list, simply because we do use a lot of dependencies and namespaces in modmore extras and modmore users know they can reach out for help with those extras, or perhaps there’s something we’re doing that’s triggering this problem. I do know the issue with FormIt was reported in 2018 but I started seeing this a lot more often in the last two months.
I’ve found that optimizing the autoloader can help. E.g., when creating the package we use the command
composer install --prefer-dist --no-dev --no-progress --optimize-autoloader, or running that in the
core/components/<package>/ folder of an extra that’s breaking fixes it for that extra. But it doesn’t avoid other extras breaking that do not have an optimized autoloader, so it seems that this is a workaround and not the actual root problem/solution.
I’m out of ideas on where to look and really want to know what’s going on here.
So, if anyone has any other ideas on how to tackle this, I’m offering a €300 bounty for the person to identify the problem or find a fix. If someone doesn’t identify the problem or find the fix, but still provide the hint/clue that leads into the rabbit hole where the problem/fix is located, half that amount is theirs.
Happy to provide more information anyone thinks may help, but I do want to note it’s been happening with different combinations of extras on different servers running different versions of MODX and PHP (modmore extras require at least PHP 7.1).
Composer version used to build modmore extras is 1.10.10 on PHP 7.4. These composer/php versions have been recently updated but if memory serves me right (often it doesn’t) that was after the first time someone reported an issue like this, and I’m also not yet convinced this is modmore-specific as it first happened with formit… but can’t rule it out either.
Updated Sept 28: I’m going to try and keep a list of sites that are affected and their PHP version and installed extras, to hopefully figure out the combination or eliminate specific extras. Only one site per business that has an affected site as they’re likely to use similar setups for different sites.
Support ticket numbers (for my reference) in brackets.
- PHP 7.4.4, MODX 2.7.3: Ace 1.8.0-pl, Big Brother 1.4.1-pl, ClientConfig 2.3.0-pl, Commerce 1.2.0-rc2, controlErrorLog 1.4.0-beta, Formit 4.2.5-pl, getCache 1.1.0-pl, pdoTools 2.12.7-pl, pThumb 2.3.3-pl, Quickstart Buttons 1.3.0-pl, Redactor 3.0.1-pl, Resizer 1.0.2-beta, SiteDash Client 1.3.3-pl, statcache 1.4.0pl, ToggleTVSet 1.2.6-pl, UpgradeMODX 2.1.2-pl, VersionX 2.3.2-pl [S24387]
- PHP 7.4.10, MODX 2.7.3: Ace 1.8.0-pl, Alpacka 1.0.0-pl, Big Brother 1.4.1-pl, ClientConfig 2.3.0-pl, Collections 3.7.1-pl, Commerce 1.2.0-rc2, CommerceTheme Red 1.0.2-pl, Formula Shipping 1.1.0-pl, MyParcel dev3, PackingSlip 1.1.2-pl, TableRates 1.1.2-pl, CSRF Helper 1.0.0-pl, fastField 1.4.0, FormIt 4.2.5-pl, getPage 1.2.4-pl, getRelated 1.2.0-pl, getResources 1.6.1-pl, If 1.1.1-pl, Login 1.9.9-pl, MIGX 2.12.0-pl, MoreGallery 1.11.1-pl, pdoTools 2.12.7-pl, pThumb 2.3.3-pl, ReCaptchaV2 3.2.1-beta1, Redactor 3.0.1-pl, Resizer: 1.0.2-beta, SEO Pro 1.3.1-pl, SiteDash Client 1.3.3-pl (not installed), SEO Tab 2.2.0-pl, SuperBoxSelect 2.4.1-pl, Tagger 1.11.0-pl, VersionX 2.3.2-pl [S24344]
In common: PHP 7.4, MODX 2.7.3, Ace, Big Brother, ClientConfig, Commerce, FormIt, pdoTools, pThumb, Redactor, SiteDash Client, VersionX