Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#48059 closed defect (bug) (fixed)

Check PHP and MySQL requirements as early as possible

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: has-patch
Focuses: Cc:

Description

Background: #47678

As noted in comment:58:ticket:47678, wp-includes/plugin.php cannot currently use PHP 5.6+ function signatures. For example, replacing func_get_arg() in do_action() with the spread operator: do_action( $tag, ...$arg ) causes a fatal error on older PHP versions:

Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in wp-includes/plugin.php on line 442

instead of displaying a proper error message:

Your server is running PHP version 5.2.17 but WordPress 5.3-alpha-45282-src requires at least 5.6.20.

Upon some investigation, it looks like the PHP version check is done a bit too late in the process flow.

Just moving the check earlier doesn't help, as wp_load_translations_early() includes wp-includes/plugin.php for do_action() and apply_filters() calls in l10n.php.

Moving the check earlier along with removing wp_load_translations_early() for this error message appears to work as expected. I believe the performance improvements from using modern PHP code outweigh the benefits of having this particular string translated.

At the moment, these 12 files (apart from wp-settings.php) need to be parsable by older PHP versions to display a proper error message:

wp-includes/load.php
wp-includes/class-wp-paused-extensions-storage.php
wp-includes/class-wp-fatal-error-handler.php
wp-includes/class-wp-recovery-mode-cookie-service.php
wp-includes/class-wp-recovery-mode-key-service.php
wp-includes/class-wp-recovery-mode-link-service.php
wp-includes/class-wp-recovery-mode-email-service.php
wp-includes/class-wp-recovery-mode.php
wp-includes/error-protection.php
wp-includes/default-constants.php
wp-includes/plugin.php
wp-includes/version.php

With the patch, the number of files that need to remain parsable by older PHP versions is reduced to just two:

wp-includes/version.php
wp-includes/load.php

Attachments (1)

48059.diff (3.0 KB) - added by SergeyBiryukov 5 years ago.

Download all attachments as: .zip

Change History (3)

@SergeyBiryukov
5 years ago

#1 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 46183:

Bootstrap/Load: Reorganize the initialization flow so that the check for PHP and MySQL requirements could run as early as possible.

This allows us to use PHP 5.6+ syntax in more files, and display a proper error message on older PHP versions, instead of causing a parse error.

Fixes #48059.

This ticket was mentioned in Slack in #core-site-health by sergey. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.