Switching to PHP 8.x in 4 Steps – An Interview with Juliette Reinders Folmer

by | Mar 3, 2023 | Etcetera | 0 comments

Upgrading a WordPress internet web page, plugin, or theme to a brand spanking new version of PHP is a role that recurs frequently. On the other hand how do you do this as effectively as possible? How do you know you received’t forget anything? Is there a roadmap for it?

In this article, we’ll tackle the ones questions (and further) and take a look at what’s thinking about a blank transition to PHP 8.x on your WordPress internet web page, plugin, or theme, in conjunction with a roadmap.

We’ll do this based on an interview we carried out with PHP skilled Juliette Reinders Folmer. She devotes most of her daily life to programming and the entire thing spherical it, focusing mainly on open-source tasks, in conjunction with WordPress.

Can you make the switch simply too? Thinking about our step-by-step plan? Then let’s dive correct in!

PHP 8.x — What’s Changed

For an overview of the changes, we advise the articles beneath:

After learning the ones articles, you’re going to be completely up to the moment on what has changed in PHP 8.x and what you want to do to get your PHP tasks operating without any problems.

For individuals who’re not sure what some of the highest techniques to start out is, no problem. Inside the conversation with Juliette, we discussed this in detail, and we will explain to you in this article as completely as possible the way you’ll be capable of switch to PHP 8.x.

We can moreover explain in informative containers simple how to perform quite a lot of operations in MyKinsta, our proprietary keep an eye on panel for all of your WordPress web pages, programs, and databases.

Switching to PHP 8.x: How To Get Started

Switching to PHP 8.x sounds simple, and technically, it’s. Many hosts assist you to specify which version of PHP you want to use on your internet web page throughout the admin panel. At Kinsta, switching the PHP edition may also be completed with a single click on on throughout the MyKinsta dashboard.

On the other hand forward of you do, there are some things you want to ensure of. Depending on your level of data and enjoy, we advise the following:

  • If you have built your own WordPress internet web page with usual subjects and plugins, without having so much knowledge of PHP, hire a developer or corporate to research whether or not or no longer your internet web page is appropriate to run on PHP 8.x. Are you looking for a third celebration that let you with this? Then take a look at our Companions web page report various trusted companies that can assist you.
  • If your WordPress internet web page used to be as soon as built via an external celebration, a developer, or an corporate, contact them to ask if your internet web page can run on PHP 8.x.
  • If you have built your WordPress internet web page — with your own custom designed theme, for instance, or self-developed plugins — now now we have a roadmap for you beneath.

If your internet web page falls into some of the an important first two categories, we indubitably invite you to be informed via the rest of the item, on the other hand we don’t suggest you get began testing your internet web page for PHP 8 compatibility yourself. Move away it to the professionals.

Regardless of you choose, we may advise you not to merely switch your reside internet web page to PHP 8 and “see if it in reality works.” Are you interested by what your internet web page will appear to be, and also you’ll be capable of’t wait to appear it operating on PHP 8? Then get began testing within a staging environment. A good host will assist you to merely arrange a staging atmosphere.

MyKinsta - Create a new environment
MyKinsta – Create a brand spanking new environment

Inside the staging environment, you’ll be capable of activate PHP 8.x and see if this change works well in conjunction with your internet web page. It’s in most cases possible to artwork with a space reproduction of your internet web page. With our unfastened DevKinsta building instrument, you’ll be capable of merely import your internet web page from the MyKinsta dashboard, and then you definitely’ll be capable of exchange the PHP version to 8.0 or 8.1.

For individuals who don’t see any problems throughout the staging environment, it doesn’t necessarily suggest there aren’t in reality any problems. The roadmap beneath will assist you to know why.

PHP 8.x Compatibility Checking out: The Roadmap

Checking out: the important thing word to only proper tool. Even for WordPress web websites and their parts, identical to subjects, plugins, and the WordPress core, testing is easy methods to ensure that problems don’t happen that you simply don’t want to happen.

A tool development project consists in huge a part of testing. In this article, we look particularly at the checks that let you make the transition to PHP 8.x transfer simply. In our article on DevOps Apparatus, you’ll find a segment with a choice of gear you’ll be capable of use.

See also  New Endeavor Grade Hourly Web hosting Backups (Handiest $5/m!)

The following sorts of checks are discussed in this blog post:

Let’s look further moderately at the different types of checks we can perform.

Static Analysis (or Static Checking out)

The first step you’ll be capable of take as a PHP developer is to perform a static analysis of your code with quite a lot of equipment. Static analysis is the process of analyzing tool without executing the code. With static analysis, it’s possible to find errors, uncover problems with PHP 8.x compatibility, put in force coding necessities (for instance, the WordPress Coding Requirements), and even modifying and cleaning up the code is possible.

Apparatus for Static Analysis

You’ll be capable of perform a static analysis with quite a lot of equipment, identical to:

At the time of writing, not all PHP 8.1 checks are supported in the newest PHPCompatibility unencumber. PHP 8.1 checks may also be throughout the development unencumber, so be sure you use those (for now) when using PHPCompatibility to analyze your project and see what errors/ideas there are.

PHP 8.1 checks will briefly be introduced in a brand spanking new number one version. If you want to be stored up to the moment on this, and you have a GitHub account, open GitHub repository of PHPCompatibility and navigate to Watch -> Custom designed -> Releases, where you’ll be ready to choose to be notified when a brand spanking new version is introduced.

PHPCompatibility, which highest checks compatibility for a decided on version (or range of permutations) of PHP, is modest to organize. You get the best results for many who run a testVersion — for instance, 8.0+ (8.0 and up) — within PHPCompatibility.

You should be looking out for deprecated or deleted functions, changed default values of function parameters, whether or not or to not employ concat without parenthesis, whether or not or to not employ are compatible as a function establish (because it’s been reserved since PHP 8.0), and so forth.

Screenshot from the PHPCompatibility GitHub page
Screenshot from the PHPCompatibility GitHub internet web page

Psalm and PHPStan are good additions and let you via performing additional checks related to variable types. The disadvantage of the ones equipment is that it takes a large number of configuration to get tales on PHP 8.0 and 8.1. Even though they’re a success, you’ll be capable of expect many false positives. False positives are notifications which may well be given wrongly, led to throughout the restrictions of static analysis.

Sound knowledge is had to appropriately interpret the results of the ones two equipment, on the other hand that knowledge let you decide additional incompatibilities that PHPCompatibility can’t to search out. Take a look on the documentation for Psalm and PHPStan if you want to be told further about them.


  • Perform static analysis with PHPCompatibility, Psalm, PHPStan
  • Get to the bottom of all skilled problems
MyKinsta - viewing log files
MyKinsta – viewing log information

Unit Checking out

The next step throughout the process is unit testing. Unit testing is a method of testing pieces of code in my view. In unit testing, specific targeted checks will likely be complex for each unit. This will likely now and again comprise operating via different scenarios. Preferably, each situation is tested one at a time from the others so that the checks are independent of one another.

Having unit checks on my own, in any case, isn’t enough. As well as they need to be run. Unit checks are absolute best computerized using CI (secure integration) tooling identical to Jenkins, GitHub Movements, or Travis.

An example from GitHub Actions
An example from GitHub Actions

Supporting A few Permutations of PHP

As a plugin builder, if you want to support a couple of PHP permutations, be certain the checks in CI are run towards all PHP permutations you support.

In spite of everything, you’ll be capable of moreover support highest newer permutations, the choice is absolutely up to you.

Checking out with a couple of permutations of PHP requires that you simply use a couple of PHPUnit permutations, depending on the PHP version. Since PHPUnit has introduced various changes over time that affect how checks are written, this phase may also be difficult.

To get spherical this, you’ll be capable of use the PHPUnit Polyfills (written via Juliette and subsidized via Yoast). This permits you to write checks which may well be officially unsupported for PHPUnit 9 (and thus can run on PHP 8.x). The Polyfills then make your checks artwork in PHPUnit 4.x via 9.x and with PHP 5.4 via PHP 8.1 (as of now).[/notice]

Now that you simply’ve were given the checks operating, the next step is to make sure the problems found out throughout the checks are mounted.

Code Coverage

Operating the ones checks is basically essentially the most unswerving method to to search out cross-version incompatibilities.

In doing so, take note of the code coverage of your checks:

  • Think you’ve a function A and have written a test for it, and function A decision functions B, C, and D as part of the common-sense throughout the function.
  • The test for function A is written to test the common-sense of function A, on the other hand it’ll moreover identify functions B, C, and D all the way through testing. For functions B, C, and D, then you definitely definately maximum frequently highest test the “happy path” — the location where the entire thing goes well — and thus, those functions are also not however completely tested, despite the fact that (part of) the code within the ones functions is completed all the way through the testing of function A.
  • For each of your checks, indicate which code is particularly being tested. You do this via giving each test a @covers This way, B, C, and D don’t appear to be “counted” throughout the code coverage calculation, which helps you to see what part of your code is covered via checks.
See also  Ecommerce Conversion Charges Throughout Industries (And Find out how to Carry Yours)

Incessantly developers write and test — now and again even unknowingly — for the “happy path.” In the ones cases, testing what happens when unexpected data is passed to a function may be necessary. Checking out with highest expected values/types isn’t enough.

”In checking out you wish to have to be sure that a serve as does what it must do, but additionally {that a} serve as does not do what it mustn’t.” – Juliette Reinders FolmerClick on to Tweet

The second part of the above quote is often forgotten, when it’s possibly a lot more very important than the main phase. What happens for many who transfer an mistaken type? Do you get an error message? Or is the variable solid with the function continuing as commonplace? What if an unexpected value is passed to the function?

Be sure to test your functions with unexpected variables, types, and values. Simplest then can you rely on your checks to go looking out problems {{that a}} new PHP version would perhaps explanation why.

PHP Is Getting Stricter

PHP is turning into further precise (strict) in how it handles “types” for PHP’s private functions, along with things like dynamic properties. The ones changes are most often intended to have the same opinion developers send error-free code (well, code with fewer errors). On the other hand this may increasingly supply quite an give a boost to hurdle for pre-existing code written based on the “earlier” tenets of PHP.

As a result of this power for added helpful error messages in PHP, you’ll be capable of see that making present code suitable with new PHP permutations takes increasingly time. Making code that worked on PHP 5.6 suitable for PHP 7.0 highest took a fraction of the time in most cases compared to upgrading code to make it suitable for PHP 8.1. And that’s even supposing PHP 7.0 used to be as soon as a “number one” unencumber, while PHP 8.1 is a “minor.”

In a variety of cases, testing remains to be the only unswerving method to come to a decision what should be modified to support a brand spanking new version.

Unit testing is possible with quite a lot of equipment, in conjunction with:

A lot of the ones equipment are built based on, or along side, PHPUnit.

After all, it doesn’t subject what equipment you utilize. The most important issue is that you simply test, and get the checks operating on new PHP permutations. This step can now and again be very difficult, on the other hand fortunately, as mentioned earlier, there are equipment for this, identical to PHPUnit Polyfills.

Integration Checking out

Integration testing is the next step we will perform, after static analysis and unit testing. An integration test is where real-life eventualities are tested in a larger context than just a “code unit.” The ones include testing with an full of life (test) database or testing with an external API, to provide merely two examples.

So, when you test the code of a plugin or theme throughout the context of WordPress and use a real version, the ones are, via definition, integration checks.

WP Test Utils (another time written via Juliette and subsidized via Yoast) is an excellent software for integration testing. WP Test Utils provides tooling to write integration and unit checks, right through which WordPress is “mocked up” using Brainmonkey and Mockery, where often used WordPress functions are “faked” in order that you’re testing your own code and not the WordPress code.

WP Test Utilities on GitHub
WP Test Utilities on GitHub

Integration testing with WordPress is a trickier story because it involves integration with WordPress and WordPress’ test suite. Depending on which permutations of WordPress a plugin or theme is helping, it’s necessary to consider which PHPUnit permutations are supported via WordPress itself to run the checks on different PHP permutations.

For example, WordPress 5.6 via 5.8 uses PHPUnit 5 thru 7 for testing PHP 5.6 thru PHP 8.0, on the other hand as of WordPress 5.9, WordPress itself moreover uses PHPUnit Polyfills for broader support. WP Test Utils acts as a bridge to overcome numerous those permutations.

Need to be told further about simple how to run integration checks towards a couple of different permutations of WordPress, in conjunction with WordPress 5.9 and above? Then examine it on WordPress’ web site.

Information Checking out

Now that you simply’ve gone via unit testing and integration testing and have mounted all the issues you found out, it’s time to do manual testing. Your internet web page is operating, and your own code is working, on the other hand you’re moreover using plugins A, B, and C. Have you learnt if those plugins fit?

For example, check out this with the plugin’s authors and see within the tournament that they indicate that it’s PHP 8.x appropriate. The question then, in any case, is how the plugin used to be as soon as tested. Incessantly the answer that is: in isolation. The plugin’s functions have maximum frequently been tested along side WordPress on my own, without other full of life plugins. And although other plugins have been used within the ones checks, chances are high that that not all plugins used by you have been part of the testing, so take this type of compatibility commentary with a grain of salt.

For example, a WordPress internet web page with 3 plugins (A, B, and C). It’s possible that plugin B, for instance, returns an mistaken variable type by the use of a filter, which plugin C, using the an identical filter, needs to artwork with. This will likely then explanation why a dangerous error given that type is not what is predicted. Plugin C is then noticed since the wrongdoer for the error message, even if plugin B is the true wrongdoer.

Plugin interoperability-incompatibilities are impossible to search out when testing in isolation. The additional full of life plugins, the a lot more most probably something will transfer flawed. For example, it’s going to be very in reality useful to transport internet web page requests from a reside internet web page to a staging environment (with error logging enabled) to search out what’s in reality going flawed.

See also  A Complete Information To Laravel Authentication

With this sort of problem, a internet web page owner will maximum frequently highest see a message that there used to be as soon as an error with the final completed code (in this case, from plugin C), even if plugin C isn’t necessarily the cause of the problem.

Maximum frequently, a large number of manual, human artwork is worried, and a healthy amount of elbow grease is had to uncover and fasten the ones problems. This would possibly be computerized using end-to-end testing, on the other hand we don’t see this going down so much in WordPress.

Test Availability for Carried out Plugins

For developers and development teams: Accept code highest when checks are available. This way, you ensure that a lot much less manual testing is wanted, which saves you a large number of time.

Question its testing method if you want to acquire a business plugin or theme. That manner, we collectively create awareness among developers/development teams throughout the WordPress crew to get testing higher on the agenda, and all folks benefit.

Checking out is often thought to be — unfairly — as a value when, in fact, it saves money. The extra investment required to write checks will repay inside the kind of significantly fewer bug tales and less time spent fixing bugs. In addition to, with computerized tool testing, extensions and adjustments may also be completed sooner given that checks can speedily verify that present capacity continues to artwork.

”Be sort on your long term self, please ;-)” – Juliette Reinders FolmerClick on to Tweet

The Serve as of WordPress Hosts and PHP 8.x

For the standard internet web page owner, guidance from your host may be very attention-grabbing. Consider the following:

  • Documentation and updates for purchasers that WordPress Core, plugins, and/or subjects are (in some cases) not PHP cross-version appropriate
  • Possible choices for testing (identical to running with a staging atmosphere)
  • Methods for error reporting and contacting support

This moreover benefits a web host, as internet web page house owners often contact the host for have the same opinion when problems stand up. Relating to a switch to PHP 8.0 or 8.1, the internet web page owner is responsible for possible problems, and the extra data the owner has to appropriately get able for the switch, the better.

Making PHP 8.0 or 8.1 available to consumers as a web host is one thing, on the other hand in doing so, they must make sure you create awareness among consumers in order that they’re mindful that problems would perhaps flooring. Checking out your internet web page in a staging environment with a unique version than reside is in reality helpful. (Settling on PHP permutations is to be had through default at Kinsta.)

Minimum PHP Style for WordPress

Over 15% of all web websites in recent times use PHP version 7.0 or lower. This may also be noticed throughout the legitimate WordPress statistics. About 83% of all WordPress web pages in recent times use PHP version 7.4 or lower. Please apply that anything lower or identical to version 7.4 is in recent times now not supported through PHP. The use of end-of-life permutations of PHP can lead to problems because of protection updates are actually no longer introduced.

To steer clear of problems, it’s very important that WordPress internet web page house owners are conscious about and a professional on the minimum PHP version that may allow their internet web page to run safely. For their phase, internet web page house owners can keep an eye on the PHP version themselves (conceivable at Kinsta for all applications) or ask their host to exchange the internet web page to a newer PHP version. In over the top cases, you’ll be capable of switch to a host that is helping the ones newer permutations.

Because of WordPress highest requires a minimal edition of seven.4, there’s insufficient motivation for quite a lot of hosts and internet web page house owners to exchange their web pages. And that’s even supposing PHP 7.4 reached its end-of-life in November 2022.

If WordPress ever does building up the minimum PHP version, this will likely now and again suggest that many web pages will not be appropriate with an change to the newest WordPress version. On the other hand, protection updates will continue to be introduced for those old-fashioned permutations for quite some time.


To switch to PHP 8.0 or higher on your internet web page, there are a selection of steps that you simply, or your developer, must perform. Vital steps include:

  • Static analysis
  • Unit testing
  • Integration testing
  • Information testing

When switching to PHP 8.x, be certain the entire thing has been appropriately tested. That’s the one method to ensure that your internet web page will run appropriately, quickly, and securely on a newer PHP version.

We thank Juliette immensely for taking part in this article and for all her artwork on the equipment mentioned!

Image of Juliette, taken via Jip Moors and used with permission.

The post Switching to PHP 8.x in 4 Steps – An Interview with Juliette Reinders Folmer appeared first on Kinsta®.

WP Hosting

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more


Submit a Comment

Your email address will not be published. Required fields are marked *