Fixed PHP 8.0 incompatibility: libxml_disable_entity_loader deprecated

Affected version
2.2.1

PaulB

Active member
libxml_disable_entity_loader has been deprecated in PHP 8.0; it's no longer necessary to call that function.

Currently, on PHP 8.0, this results in exceptions when installing XFES 2.2.0 (and possibly all other add-ons, but I haven't yet checked):

Code:
ErrorException: [E_DEPRECATED] Function libxml_disable_entity_loader() is deprecated in src/XF/Util/Xml.php at line 33
XF::handlePhpError() in src/XF/Util/Xml.php at line 33
XF\Util\Xml::open() in src/XF/Util/Xml.php at line 20
XF\Util\Xml::openFile() in src/XF/AddOn/DataType/AbstractDataType.php at line 53
XF\AddOn\DataType\AbstractDataType->openTypeFile() in src/XF/Job/AddOnData.php at line 60
XF\Job\AddOnData->run() in src/XF/Job/Manager.php at line 258
XF\Job\Manager->runJobInternal() in src/XF/Job/Manager.php at line 200
XF\Job\Manager->runJobEntry() in src/XF/Job/Manager.php at line 116
XF\Job\Manager->runByIds() in src/XF/Admin/Controller/Tools.php at line 120
XF\Admin\Controller\Tools->actionRunJob() in src/XF/Mvc/Dispatcher.php at line 350
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 257
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 113
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 55
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2300
XF\App->run() in src/XF.php at line 465
XF::runApp() in admin.php at line 13
 

djbaxter

Well-known member
I'm assuming that PHP 8 is still not at the stable release stage, correct? And most hosts are not even showing this as an option yet. That said, it looks interesting and I'm sure Xenforo will be upgraded in due course then PHP8 is stable.


It’s a new major edition, which means that it will bring some breaking changes, as well as lots of new features and performance improvements.

There’s a greater chance that you’ll need to make some improvements in your code to get it running on PHP 8 because of the breaking improvements. If you’ve stayed up to date with the new releases though, the update shouldn’t be too hard, because most breaking changes were deprecated before in the 7. * versions.


When will PHP 8 be released?
After a lot of to-ing and fro-ing as to when PHP 8 would be released, the developers have now announced that November 26th, 2020 is the date we’re waiting for. This corresponds to the normal three-year cycle for releasing an updated PHP. PHP 7.4 was released in December 2019 and the support for PHP 7.1 has been discontinued.


PHP 8 is expected to be released in December 2020 and will bring us a whole bunch of powerful features and great language improvements.

Many RFCs have already been approved and implemented, so it’s time for us to dive into some of the most exciting additions that should make PHP faster and more reliable.

As PHP 8 is still under development, we could see several changes before the final release.
 

PaulB

Active member
I'm assuming that PHP 8 is still not at the stable release stage, correct?

Correct; it'll be out next month.

And most hosts are not even showing this as an option yet.

Larger forums tend not to use shared hosting, so they can use whatever version of PHP they like. When developing internal add-ons, PHP 8 is nice because it brings a lot of useful features for developers. Forums that have completely control over their stack and development process are likely to opt for PHP 8 as soon as it's released, which will be quite soon.

Ideally, simple compatibility issues should be fixed before the stable release. There's no need to wait until a stable release once the feature freeze is hit.
 

Chris D

XenForo developer
Staff member
@djbaxter we do not wait for PHP to become stable before implementing changes. We already had to catch a bunch of potentially breaking changes for PHP 8.0 during development of XF 2.2 so for the most part XF 2.2 is already compatible.

We’ll hopefully get these last changes in for full compatibility in time for its stable release.
 

djbaxter

Well-known member
Not so fast. It's not necessarily that easy when there are still a lot of Xenforo customers on previous versions of PHP.



Additionally, people running other software, including WordPress, need to exercise caution and ensure that their hosting allows them to not run PHP 8 yet for those installations.


Should I upgrade right away?​

No. The upcoming major version of WordPress, 5.6, is intended to be “beta compatible with PHP 8” according to the November 18 WordPress dev chat. This means that most core WordPress functionality will work, but unexpected bugs may still occur for some time, even without the presence of additional plugins or themes. WordPress has called for additional testing with PHP 8 in order to find and fix as many remaining bugs as possible.

At Wordfence, our Quality Assurance team is working to ensure that our plugin is compatible with PHP 8 in a variety of environments. Upcoming Wordfence versions will offer a similar level of partial support, though we have additional testing planned to reach full compatibility.

A vast number of WordPress plugins and themes will not be immediately compatible with PHP 8. Those that do not run into fatal errors during normal usage may still show unexpected behavior for some time. ...

PHP 8 uses much stricter typing than previous versions. Many built-in functions are now pickier about the input they accept, and PHP 8 itself is more stringent about how input is passed to functions. Issues that previously resulted in notices now result in warnings, and issues that previously resulted in warnings now result in errors.

In other words, PHP 8 is not as lenient as previous versions. It will not try quite as hard to make code work no matter what.

Some functions and features that were deprecated in PHP 7.x have been completely removed. These include:
  • The $php_errormsg variable
  • The create_function() function
  • The mbstring.func_overload ini directive
  • The real type
  • The allow_url_include ini directive
  • The restore_include_path() function
  • The each() function
While most of these are no longer widely used, we have identified that create_function is still used in over 5,500 WordPress plugins, including extremely popular plugins with millions of installations. In some cases use of these deprecated functions may be intended for backwards compatibility with older versions of PHP. Many plugins, however, will need extensive refactoring as PHP 8 becomes more utilized.

Quite a few plugins and themes also depend heavily on third party libraries. WordPress developers may need to wait until these are updated for compatibility. If these libraries are not maintained or updated for compatibility with PHP 8, it may be necessary to fork these libraries, find alternatives, or even rewrite plugins and themes from the ground up.

For more in-depth information about what’s changed, our friends at Yoast have produced an excellent compatibility report intended for developers looking to ensure their software is compatible.
 
Top