Code Modernization: Replace phpversion() function calls with PHP_VERSION constant.

`phpversion()` return value and `PHP_VERSION` constant value are identical, but the latter is several times faster because it is a direct constant value lookup compared to a function call.

Props ayeshrajans, jrf, mukesh27, costdev, hellofromTonya, SergeyBiryukov.
Fixes #55680.

git-svn-id: https://develop.svn.wordpress.org/trunk@53426 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-05-20 17:36:23 +00:00
parent 674ed76aa1
commit 5a49274a92
19 changed files with 32 additions and 37 deletions

View File

@ -266,7 +266,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
$error = sprintf(
/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
phpversion(),
PHP_VERSION,
$requires_php
);

View File

@ -447,7 +447,7 @@ class Plugin_Upgrader extends WP_Upgrader {
$error = sprintf(
/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
phpversion(),
PHP_VERSION,
$requires_php
);

View File

@ -301,7 +301,7 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
$error = sprintf(
/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
phpversion(),
PHP_VERSION,
$requires_php
);

View File

@ -599,7 +599,7 @@ class Theme_Upgrader extends WP_Upgrader {
$error = sprintf(
/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
phpversion(),
PHP_VERSION,
$requires_php
);

View File

@ -222,7 +222,7 @@ class WP_Automatic_Updater {
if ( 'core' === $type ) {
global $wpdb;
$php_compat = version_compare( phpversion(), $item->php_version, '>=' );
$php_compat = version_compare( PHP_VERSION, $item->php_version, '>=' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
$mysql_compat = true;
} else {
@ -236,7 +236,7 @@ class WP_Automatic_Updater {
// If updating a plugin or theme, ensure the minimum PHP version requirements are satisfied.
if ( in_array( $type, array( 'plugin', 'theme' ), true ) ) {
if ( ! empty( $item->requires_php ) && version_compare( phpversion(), $item->requires_php, '<' ) ) {
if ( ! empty( $item->requires_php ) && version_compare( PHP_VERSION, $item->requires_php, '<' ) ) {
return false;
}
}

View File

@ -677,23 +677,18 @@ class WP_Debug_Data {
$server_architecture = 'unknown';
}
if ( function_exists( 'phpversion' ) ) {
$php_version_debug = phpversion();
// Whether PHP supports 64-bit.
$php64bit = ( PHP_INT_SIZE * 8 === 64 );
$php_version_debug = PHP_VERSION;
// Whether PHP supports 64-bit.
$php64bit = ( PHP_INT_SIZE * 8 === 64 );
$php_version = sprintf(
'%s %s',
$php_version_debug,
( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
);
$php_version = sprintf(
'%s %s',
$php_version_debug,
( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
);
if ( $php64bit ) {
$php_version_debug .= ' 64bit';
}
} else {
$php_version = __( 'Unable to determine PHP version' );
$php_version_debug = 'unknown';
if ( $php64bit ) {
$php_version_debug .= ' 64bit';
}
if ( function_exists( 'php_sapi_name' ) ) {

View File

@ -1385,7 +1385,7 @@ function verify_file_signature( $filename, $signatures, $filename_for_errors = f
'<span class="code">' . esc_html( $filename_for_errors ) . '</span>'
),
array(
'php' => phpversion(),
'php' => PHP_VERSION,
'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
)
);
@ -1420,7 +1420,7 @@ function verify_file_signature( $filename, $signatures, $filename_for_errors = f
'<span class="code">' . esc_html( $filename_for_errors ) . '</span>'
),
array(
'php' => phpversion(),
'php' => PHP_VERSION,
'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
'polyfill_is_fast' => false,
'max_execution_time' => ini_get( 'max_execution_time' ),
@ -1493,7 +1493,7 @@ function verify_file_signature( $filename, $signatures, $filename_for_errors = f
'hash' => bin2hex( $file_hash ),
'skipped_key' => $skipped_key,
'skipped_sig' => $skipped_signature,
'php' => phpversion(),
'php' => PHP_VERSION,
'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
)
);

View File

@ -1524,7 +1524,7 @@ function _wp_privacy_settings_filter_draft_page_titles( $title, $page ) {
* @return array|false Array of PHP version data. False on failure.
*/
function wp_check_php_version() {
$version = phpversion();
$version = PHP_VERSION;
$key = md5( $version );
$response = get_site_transient( 'php_check_' . $key );

View File

@ -1150,7 +1150,7 @@ function validate_plugin_requirements( $plugin ) {
/* translators: 1: Current WordPress version, 2: Current PHP version, 3: Plugin name, 4: Required WordPress version, 5: Required PHP version. */
_x( '<strong>Error:</strong> Current versions of WordPress (%1$s) and PHP (%2$s) do not meet minimum requirements for %3$s. The plugin requires WordPress %4$s and PHP %5$s.', 'plugin' ),
get_bloginfo( 'version' ),
phpversion(),
PHP_VERSION,
$plugin_headers['Name'],
$requirements['requires'],
$requirements['requires_php']
@ -1162,7 +1162,7 @@ function validate_plugin_requirements( $plugin ) {
'<p>' . sprintf(
/* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */
_x( '<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ),
phpversion(),
PHP_VERSION,
$plugin_headers['Name'],
$requirements['requires_php']
) . $php_update_message . '</p>'

View File

@ -1012,7 +1012,7 @@ function update_core( $from, $to ) {
require WP_CONTENT_DIR . '/upgrade/version-current.php';
$wp_filesystem->delete( $versions_file );
$php_version = phpversion();
$php_version = PHP_VERSION;
$mysql_version = $wpdb->db_version();
$old_wp_version = $GLOBALS['wp_version']; // The version of WordPress we're updating from.
$development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' ) ); // A dash in the version indicates a development release.

View File

@ -228,7 +228,7 @@ if ( is_blog_installed() ) {
*/
global $wp_version, $required_php_version, $required_mysql_version;
$php_version = phpversion();
$php_version = PHP_VERSION;
$mysql_version = $wpdb->db_version();
$php_compat = version_compare( $php_version, $required_php_version, '>=' );
$mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );

View File

@ -59,7 +59,7 @@ function list_core_update( $update ) {
$message = '';
$form_action = 'update-core.php?action=do-core-upgrade';
$php_version = phpversion();
$php_version = PHP_VERSION;
$mysql_version = $wpdb->db_version();
$show_buttons = true;

View File

@ -44,7 +44,7 @@ global $wp_version, $required_php_version, $required_mysql_version;
$step = (int) $step;
$php_version = phpversion();
$php_version = PHP_VERSION;
$mysql_version = $wpdb->db_version();
$php_compat = version_compare( $php_version, $required_php_version, '>=' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {

View File

@ -19,7 +19,7 @@
ignore_user_abort( true );
/* Don't make the request block till we finish, if possible. */
if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
if ( PHP_VERSION_ID >= 70016 && function_exists( 'fastcgi_finish_request' ) ) {
if ( ! headers_sent() ) {
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );

View File

@ -8422,7 +8422,7 @@ function is_wp_version_compatible( $required ) {
* @return bool True if required version is compatible or empty, false if not.
*/
function is_php_version_compatible( $required ) {
return empty( $required ) || version_compare( phpversion(), $required, '>=' );
return empty( $required ) || version_compare( PHP_VERSION, $required, '>=' );
}
/**

View File

@ -143,7 +143,7 @@ function wp_populate_basic_auth_from_authorization_header() {
*/
function wp_check_php_mysql_versions() {
global $required_php_version, $wp_version;
$php_version = phpversion();
$php_version = PHP_VERSION;
if ( version_compare( $required_php_version, $php_version, '>' ) ) {
$protocol = wp_get_server_protocol();

View File

@ -32,7 +32,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) {
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
$php_version = phpversion();
$php_version = PHP_VERSION;
$current = get_site_transient( 'update_core' );
$translations = wp_get_installed_translations( 'core' );

View File

@ -27,7 +27,7 @@ class Tests_Functions_IsPhpVersionCompatible extends WP_UnitTestCase {
* @return array
*/
public function data_is_php_version_compatible() {
$php_version = phpversion();
$php_version = PHP_VERSION;
$version_parts = explode( '.', $php_version );
$lower_version = $version_parts;

View File

@ -40,7 +40,7 @@ class Tests_Load_wpIsIniValueChangeable extends WP_UnitTestCase {
array( 'upload_tmp_dir', false ), // PHP_INI_SYSTEM.
);
if ( extension_loaded( 'Tidy' ) && version_compare( PHP_VERSION, '7.0.0', '>' ) ) {
if ( PHP_VERSION_ID > 70000 && extension_loaded( 'Tidy' ) ) {
$array[] = array( 'tidy.clean_output', true ); // PHP_INI_USER.
}