Skip to content

Add support for PHP 8.x#96

Open
ara303 wants to merge 15 commits intoaaemnnosttv:masterfrom
ara303:fix/php-8.2-compat
Open

Add support for PHP 8.x#96
ara303 wants to merge 15 commits intoaaemnnosttv:masterfrom
ara303:fix/php-8.2-compat

Conversation

@ara303
Copy link

@ara303 ara303 commented Mar 15, 2026

Fixes #94.

This PR adds support for PHP 8.x versions by bumping dependency versions, and making some changes to tests so that they run under PHP 8.5 (latest stable).

Testing procedure

Tested with every minor 8.x version (8.0, 8.1, 8.2, 8.3, 8.4, and 8.5). Development and testing was done on 8.5.

Commands run on every version:

  • composer validate --strict
  • composer install
  • wp valet new <name>

Commands run on 8.5:

  • composer behat

Tests pass:

14 scenarios (14 passed)
104 steps (104 passed)
1m4.04s (11.96Mb)

PHP 8.5 notes

Because 8.5 is so recent, I needed to use the nightly build of WP-CLI to avoid (harmless) noise: wp cli update --nightly (version: WP-CLI 2.13.0-alpha-b0f2aec).

Additionally, one warning shown by composer install (and update):

Package roots/wp-password-bcrypt is abandoned, you should avoid using it. Use roots/wp-password-bcrypt instead.

roots/wp-password-bcrypt is abandoned now bcrypt is in WP core as of 6.8. We need to just ignore that for the time being.

Changes made to tests

I tried to run the tests under every minor PHP 8.x version but couldn't due to dependency issues. PHP 8.0 and 8.1 (both now EOL) couldn't run it at all, but I made sure wp valet new <name> works on every 8.x version.

For the Bedrock tests, $_SERVER env vars weren't returning and those tests failed. I fixed that by using getenv() instead.

Due to being unfamiliar with SQLite, I got stuck here:

Deprecated: Method PDO::sqliteCreateFunction() is deprecated since 8.5, use Pdo\Sqlite::createFunction() instead in /private/var/folders/yf/vrmrf8mn2kz37pczv36rw8z80000gn/T/wp-cli-test-run--69b8ac214eea05.46297354/valet-test-69b8ac214f7df/web/app/db.php on line 155

I changed "run" to "try" to get it to pass, but it's imperfect.

On aaemnnosttv/wp-sqlite-db sqliteCreateFunction is currently used. There is a PR over there that fix. If you can merge that (first, ideally) I'll bump the version of aaemnnosttv/wp-sqlite-db used here and revert the test grammar.

Thank you! I've bumped the version number accordingly and also reverted the test grammar. Text above can be disregarded.

Finally, I changed from a hardcoded mysql in features/Context/FeatureContext.php to a MYSQL_BINARY env var instead. My dev setup uses mariadb and the tests intermittently failed otherwise. This PR on wp-cli/wp-cli-tests was useful.

Major version bump?

Since these changes expressly require PHP 8.x or newer (composer require php >=8.0), I was wondering if you think this release should be tagged version 2.x, or similar? Let me know if you want me to merge into a different branch accordingly.

Thanks so much. 😄

@ara303 ara303 changed the title Bump composer requirements to support PHP >8.x Bump composer requirements to support PHP 8.x Mar 16, 2026
@ara303 ara303 mentioned this pull request Mar 16, 2026
@ara303 ara303 changed the title Bump composer requirements to support PHP 8.x Add support for PHP 8.x Mar 17, 2026
Copy link
Owner

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks for the PR!

I'd be happy to merge it but I wanted to avoid requiring PHP 8 just yet and it turns out that doesn't seem to be necessary. See #97

Note that PR also updates the test matrix to run tests with PHP 8.5 👍

Do you want to update this one to match or do you want to update this to be a follow up with the db enhancement?

* @Then /^the ([^\s]+) database should( not)? exist$/
*/
public function theGivenDatabaseShouldNotExist($database_name, $should_not_exist = false) {
$mysql_binary = $this->variables['MYSQL_BINARY'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem related to PHP 8.5 but happy to include it 👍

@ara303
Copy link
Author

ara303 commented Mar 20, 2026

Thanks so much for reviewing, @aaemnnosttv! 😄

Having checked out #97, the tests fail under mariadb. Could I hazard a guess your dev env uses mysql?

My theory being there's some small implementation differences in mysql vs. mariadb causing issues for the tests. This comment on wp-cli/wp-cli-tests tipped me off that there may be quirks, although I admit I didn't dig deep to understand it in detail.

Your PR wouldn't be able to use MYSQL_BINARY because it wasn't added until 4.3.13. Yours doesn't change that but probably should, to fully support mariadb.

I agree it would be better to not break compatibility in principle. I started out trying to do that but had so many roadblocks that I just couldn't. When I got fed up enough to set 8.0 as the platform version, everything got a lot easier!

Would you instead be amenable to merging these changes under a 2.x.x tag instead? You'd then be able to preserve the old version for 7.4 or older that way (FWIW, PHP 7.4.33 has been EOL since Nov 2022).

If I may opine, it doesn't strike me as particularly likely that into 2026 many developers are using Laravel Valet to run 7.4 and install a new WP version. (Not saying people don't need to work on projects running a seven year old PHP version, but unlikely to be starting new projects under it).

Either way, if you're feeling you'd prefer not to have 8.0 as a minimum version, perhaps I can figure something out. Thanks again.


Update: Figured it out! It wasn't differences between mariadb vs. mysql but macOS vs. Ubuntu. I worked on this PR using macOS 15.7.4, PHP 8.5.4, and Mariadb 12.2.2, where tests didn't pass. Upon switching to Ubuntu (24.04.4), tests passed. Some of my changes here may seem unnecessary but are in order to have the tests succeed on macOS.

@ara303
Copy link
Author

ara303 commented Mar 21, 2026

I've pushed more commits with the goal of ensuring we don't have to bump the minimum required PHP version whilst also enabling the tests to run on macOS (more detail in prior comment).

In order for the tests to succeed on macOS with mariadb, I needed to bump wp-cli/wp-cli-tests to 4.3.13 so the MYSQL_BINARY variable is available. I then needed to change numerous tests to use "try" instead of "run". That also introduced five different deprecation warnings, but there's no alternative without bumping the minimum PHP version and dependencies.

Personally, I find this dissatisfactory. I apologise accordingly. I felt it'd be best to split this package into two major versions: 1.x.x which retains PHP <8 support, and 2.x.x which supports PHP >=8.0 cleanly and robustly into the future.

The deprecation warnings that are thrown are necessary under these requirements. It's the only acceptable middle-ground I know of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.x support

2 participants