Make WordPress Core

Changeset 53426


Ignore:
Timestamp:
05/20/2022 05:36:23 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-plugin-installer-skin.php

    r50931 r53426  
    267267                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
    268268                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
    269                 phpversion(),
     269                PHP_VERSION,
    270270                $requires_php
    271271            );
  • trunk/src/wp-admin/includes/class-plugin-upgrader.php

    r52997 r53426  
    448448                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
    449449                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
    450                 phpversion(),
     450                PHP_VERSION,
    451451                $requires_php
    452452            );
  • trunk/src/wp-admin/includes/class-theme-installer-skin.php

    r52802 r53426  
    302302                /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
    303303                __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
    304                 phpversion(),
     304                PHP_VERSION,
    305305                $requires_php
    306306            );
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r53416 r53426  
    600600                /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
    601601                __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
    602                 phpversion(),
     602                PHP_VERSION,
    603603                $requires_php
    604604            );
  • trunk/src/wp-admin/includes/class-wp-automatic-updater.php

    r53131 r53426  
    223223            global $wpdb;
    224224
    225             $php_compat = version_compare( phpversion(), $item->php_version, '>=' );
     225            $php_compat = version_compare( PHP_VERSION, $item->php_version, '>=' );
    226226            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
    227227                $mysql_compat = true;
     
    237237        // If updating a plugin or theme, ensure the minimum PHP version requirements are satisfied.
    238238        if ( in_array( $type, array( 'plugin', 'theme' ), true ) ) {
    239             if ( ! empty( $item->requires_php ) && version_compare( phpversion(), $item->requires_php, '<' ) ) {
     239            if ( ! empty( $item->requires_php ) && version_compare( PHP_VERSION, $item->requires_php, '<' ) ) {
    240240                return false;
    241241            }
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r53011 r53426  
    678678        }
    679679
    680         if ( function_exists( 'phpversion' ) ) {
    681             $php_version_debug = phpversion();
    682             // Whether PHP supports 64-bit.
    683             $php64bit = ( PHP_INT_SIZE * 8 === 64 );
    684 
    685             $php_version = sprintf(
    686                 '%s %s',
    687                 $php_version_debug,
    688                 ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
    689             );
    690 
    691             if ( $php64bit ) {
    692                 $php_version_debug .= ' 64bit';
    693             }
    694         } else {
    695             $php_version       = __( 'Unable to determine PHP version' );
    696             $php_version_debug = 'unknown';
     680        $php_version_debug = PHP_VERSION;
     681        // Whether PHP supports 64-bit.
     682        $php64bit = ( PHP_INT_SIZE * 8 === 64 );
     683
     684        $php_version = sprintf(
     685            '%s %s',
     686            $php_version_debug,
     687            ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
     688        );
     689
     690        if ( $php64bit ) {
     691            $php_version_debug .= ' 64bit';
    697692        }
    698693
  • trunk/src/wp-admin/includes/file.php

    r53060 r53426  
    13861386            ),
    13871387            array(
    1388                 'php'    => phpversion(),
     1388                'php'    => PHP_VERSION,
    13891389                'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
    13901390            )
     
    14211421                ),
    14221422                array(
    1423                     'php'                => phpversion(),
     1423                    'php'                => PHP_VERSION,
    14241424                    'sodium'             => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
    14251425                    'polyfill_is_fast'   => false,
     
    14941494            'skipped_key' => $skipped_key,
    14951495            'skipped_sig' => $skipped_signature,
    1496             'php'         => phpversion(),
     1496            'php'         => PHP_VERSION,
    14971497            'sodium'      => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ),
    14981498        )
  • trunk/src/wp-admin/includes/misc.php

    r53146 r53426  
    15251525 */
    15261526function wp_check_php_version() {
    1527     $version = phpversion();
     1527    $version = PHP_VERSION;
    15281528    $key     = md5( $version );
    15291529
  • trunk/src/wp-admin/includes/plugin.php

    r53264 r53426  
    11511151                _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' ),
    11521152                get_bloginfo( 'version' ),
    1153                 phpversion(),
     1153                PHP_VERSION,
    11541154                $plugin_headers['Name'],
    11551155                $requirements['requires'],
     
    11631163                /* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */
    11641164                _x( '<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ),
    1165                 phpversion(),
     1165                PHP_VERSION,
    11661166                $plugin_headers['Name'],
    11671167                $requirements['requires_php']
  • trunk/src/wp-admin/includes/update-core.php

    r53132 r53426  
    10131013    $wp_filesystem->delete( $versions_file );
    10141014
    1015     $php_version       = phpversion();
     1015    $php_version       = PHP_VERSION;
    10161016    $mysql_version     = $wpdb->db_version();
    10171017    $old_wp_version    = $GLOBALS['wp_version']; // The version of WordPress we're updating from.
  • trunk/src/wp-admin/install.php

    r53111 r53426  
    229229global $wp_version, $required_php_version, $required_mysql_version;
    230230
    231 $php_version   = phpversion();
     231$php_version   = PHP_VERSION;
    232232$mysql_version = $wpdb->db_version();
    233233$php_compat    = version_compare( $php_version, $required_php_version, '>=' );
  • trunk/src/wp-admin/update-core.php

    r52978 r53426  
    6060    $message       = '';
    6161    $form_action   = 'update-core.php?action=do-core-upgrade';
    62     $php_version   = phpversion();
     62    $php_version   = PHP_VERSION;
    6363    $mysql_version = $wpdb->db_version();
    6464    $show_buttons  = true;
  • trunk/src/wp-admin/upgrade.php

    r53131 r53426  
    4545$step = (int) $step;
    4646
    47 $php_version   = phpversion();
     47$php_version   = PHP_VERSION;
    4848$mysql_version = $wpdb->db_version();
    4949$php_compat    = version_compare( $php_version, $required_php_version, '>=' );
  • trunk/src/wp-cron.php

    r53300 r53426  
    2020
    2121/* Don't make the request block till we finish, if possible. */
    22 if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
     22if ( PHP_VERSION_ID >= 70016 && function_exists( 'fastcgi_finish_request' ) ) {
    2323    if ( ! headers_sent() ) {
    2424        header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
  • trunk/src/wp-includes/functions.php

    r53372 r53426  
    84238423 */
    84248424function is_php_version_compatible( $required ) {
    8425     return empty( $required ) || version_compare( phpversion(), $required, '>=' );
     8425    return empty( $required ) || version_compare( PHP_VERSION, $required, '>=' );
    84268426}
    84278427
  • trunk/src/wp-includes/load.php

    r53060 r53426  
    144144function wp_check_php_mysql_versions() {
    145145    global $required_php_version, $wp_version;
    146     $php_version = phpversion();
     146    $php_version = PHP_VERSION;
    147147
    148148    if ( version_compare( $required_php_version, $php_version, '>' ) ) {
  • trunk/src/wp-includes/update.php

    r53011 r53426  
    3333    // Include an unmodified $wp_version.
    3434    require ABSPATH . WPINC . '/version.php';
    35     $php_version = phpversion();
     35    $php_version = PHP_VERSION;
    3636
    3737    $current      = get_site_transient( 'update_core' );
  • trunk/tests/phpunit/tests/functions/isPhpVersionCompatible.php

    r53237 r53426  
    2828     */
    2929    public function data_is_php_version_compatible() {
    30         $php_version = phpversion();
     30        $php_version = PHP_VERSION;
    3131
    3232        $version_parts  = explode( '.', $php_version );
  • trunk/tests/phpunit/tests/load/wpIsIniValueChangeable.php

    r52010 r53426  
    4141        );
    4242
    43         if ( extension_loaded( 'Tidy' ) && version_compare( PHP_VERSION, '7.0.0', '>' ) ) {
     43        if ( PHP_VERSION_ID > 70000 && extension_loaded( 'Tidy' ) ) {
    4444            $array[] = array( 'tidy.clean_output', true ); // PHP_INI_USER.
    4545        }
Note: See TracChangeset for help on using the changeset viewer.