Partial fix PHP 8.2: Collection of issues

PaulB

Well-known member
Affected version
2.2.11
This is a collection of patches for PHP 8.2 compatibility issues I've encountered. It's not intended to be used on a live site and just serves as a checklist of known issues.

Currently, this includes:
  1. HTML-ENTITIES encoding is deprecated:
    1. \Symfony\Component\VarDumper\Dumper\HtmlDumper::dumpLine
    2. \Symfony\Component\DomCrawler\Crawler::addHtmlContent
  2. utf8_decode and utf8_encode are deprecated:
    1. src/vendor/dokuwiki/utf8/utf8.php: utf8_decode replaced with mb_convert_encoding to preserve existing, buggy behavior (see note below for caveats)
  3. Missing properties:
    1. \XF\AddOn\DataType\AbstractDataType: $structure
    2. \XF\Http\Stream: $stream
    3. Various GuzzleHttp stream implementations: $stream
    4. \XF\Payment\CallbackState: unknown number of properties; added #[\AllowDynamicProperties]
    5. \GuzzleHttp\Handler\CurlMultiHandler: unknown number of properties; added #[\AllowDynamicProperties]
    6. \Less_Tree: $parensInOp, $allExtends
  4. Typos in property names that only started triggering errors in PHP 8.2; previous versions of PHP supported dynamic properties:
    1. \XF\BbCode\ProcessorAction\AnalyzeUsage::initialize: $smiliesCount vs $smilieCount
    2. \XFMG\Ffmpeg\Runner::setFileName: $filename vs $fileName
  5. Deprecated callable syntax:
    1. SwiftMailer: lots of occurrences
    2. \Symfony\Component\Console\Helper\QuestionHelper::formatChoiceQuestionChoices
Omitted:
  1. Any issues that exist outside XF, XFES, XFMG, XFRM, XFI, and their included libraries. Notably, XFAws is incompatible with PHP 8.2 as of writing.
  2. The fixes for utf8_encode and utf8_decode aren't ideal. Many usages of utf8_* make incorrect assumptions about languages and encoding. For example, although this patch allows wholeWordTrimAroundLength to run without erroring, it doesn't fix wholeWordTrimAroundLength's buggy behavior with certain languages. Most bugs stemming from utf8_* usage will be minor and don't require urgent fixes, but if you're an add-on developer, it's worth reassessing how you handle string comparisons and length calculations on UTF-8 text.
 

Attachments

  • 2022-11-16-php82.diff
    56.6 KB · Views: 15
Last edited:
Thanks for this.

We've applied the non-vendor parts of the patch and the changes to utf8.php.

For the others, what we'd probably like to do is fork the vendor packages, where appropriate, and apply those fixes directly to that fork which we then still pull in via composer.

We do this in the belief that it should make incorporating other upstream changes (if any) down the line, including cases where we may move to newer versions where PHP version constraints allow, should be easier.

We've not been consistent with this, and it does make seeking out those newer versions more of a manual task but we've done this a lot, particularly with PHP 8.1 compat, ironically. This is part of our internal composer.json file which overrides the repos used in the require section:

JSON:
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/less.php"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/flysystem-eventable-filesystem"
    },
    {
        "type": "path",
        "url": "src/vendor/xenforo-ltd/polyfill-noop"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/braintree_php"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/jwt-key-mgmt"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/jwt-core"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/web-push-php"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/PHPASN1"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/guzzle"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/laminas-feed"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/laminas-loader"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/laminas-mail"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/laminas-stdlib"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/laminas-validator"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/stripe-php"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/console"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/debug"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/dom-crawler"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/process"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/var-dumper"
    },
    {
        "type": "vcs",
        "url": "https://github.com/xenforo-ltd/emoji-toolkit"
    }
]

This will get closed off when the core changes are pushed but I'll open a new report for further investigation with a new copy of the patch.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.12).

Change log:
Include PHP 8.2 compatibility fixes in non-vendor classes and utf8.php
There may be a delay before changes are rolled out to the XenForo Community.
 
I tried to install php 8.2 on my server with latest XF version, with no results. Broke the forum. Had to revert back to php 8.1.13.

This is with Apache 2.4.54 and MySQL 8.0.31.
 
@gerryvz, XenForo 2.2.12 isn't compatible with PHP 8.2 yet, which is why this is marked as "partial fix." XenForo's first-party code has been updated for compatibility, but many of the third-party libraries used by XenForo are only compatible with PHP >= 7.0, <= 8.1.

A subset of my patch that applies to XenForo 2.2.12's libraries is included here, but it's just intended as a reference, and you shouldn't use it unless you're willing to manually debug and fix issues that may arise.
 
Last edited:
@gerryvz, XenForo 2.2.12 isn't compatible with PHP 8.2 yet, which is why this is marked as "partial fix." XenForo's first-party code has been updated for compatibility, but many of the third-party libraries used by XenForo are only compatible with PHP >= 7.0, <= 8.1.

A subset of my patch that applies to XenForo 2.2.12's libraries is included here, but it's just intended as a reference, and you shouldn't use it unless you're willing to manually debug and fix issues that may arise.
Thanks. Happy to wait until things are plug and play compatible. I had just noticed that the php repositories had released php 8.2 for ubuntu recently, and downloaded it via apt.
 
Back
Top Bottom