Make WordPress Core


Ignore:
Timestamp:
10/08/2020 09:13:57 PM (6 years ago)
Author:
SergeyBiryukov
Message:

General: Replace older-style PHP type conversion functions with type casts.

This improves performance, readability, and consistency throughout core.

  • intval()(int)
  • strval()(string)
  • floatval()(float)

Props ayeshrajans.
Fixes #42918.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r49098 r49108  
    799799
    800800                // For integers which may be larger than XML-RPC supports ensure we return strings.
    801                 $_term['term_id']          = strval( $_term['term_id'] );
    802                 $_term['term_group']       = strval( $_term['term_group'] );
    803                 $_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] );
    804                 $_term['parent']           = strval( $_term['parent'] );
     801                $_term['term_id']          = (string) $_term['term_id'];
     802                $_term['term_group']       = (string) $_term['term_group'];
     803                $_term['term_taxonomy_id'] = (string) $_term['term_taxonomy_id'];
     804                $_term['parent']           = (string) $_term['parent'];
    805805
    806806                // Count we are happy to return as an integer because people really shouldn't use terms that much.
    807                 $_term['count'] = intval( $_term['count'] );
     807                $_term['count'] = (int) $_term['count'];
    808808
    809809                // Get term meta.
     
    857857        protected function _prepare_post( $post, $fields ) {
    858858                // Holds the data for this post. built up based on $fields.
    859                 $_post = array( 'post_id' => strval( $post['ID'] ) );
     859                $_post = array( 'post_id' => (string) $post['ID'] );
    860860
    861861                // Prepare common post fields.
     
    873873                        'post_excerpt'      => $post['post_excerpt'],
    874874                        'post_content'      => $post['post_content'],
    875                         'post_parent'       => strval( $post['post_parent'] ),
     875                        'post_parent'       => (string) $post['post_parent'],
    876876                        'post_mime_type'    => $post['post_mime_type'],
    877877                        'link'              => get_permalink( $post['ID'] ),
    878878                        'guid'              => $post['guid'],
    879                         'menu_order'        => intval( $post['menu_order'] ),
     879                        'menu_order'        => (int) $post['menu_order'],
    880880                        'comment_status'    => $post['comment_status'],
    881881                        'ping_status'       => $post['ping_status'],
     
    10101010        protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) {
    10111011                $_media_item = array(
    1012                         'attachment_id'    => strval( $media_item->ID ),
     1012                        'attachment_id'    => (string) $media_item->ID,
    10131013                        'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ),
    10141014                        'parent'           => $media_item->post_parent,
     
    11751175         */
    11761176        protected function _prepare_user( $user, $fields ) {
    1177                 $_user = array( 'user_id' => strval( $user->ID ) );
     1177                $_user = array( 'user_id' => (string) $user->ID );
    11781178
    11791179                $user_fields = array(
     
    16481648                }
    16491649
    1650                 return strval( $post_ID );
     1650                return (string) $post_ID;
    16511651        }
    16521652
     
    20952095                }
    20962096
    2097                 return strval( $term['term_id'] );
     2097                return (string) $term['term_id'];
    20982098        }
    20992099
     
    55675567                do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
    55685568
    5569                 return strval( $post_ID );
     5569                return (string) $post_ID;
    55705570        }
    55715571
     
    65566556
    65576557                $categories = array();
    6558                 $catids     = wp_get_post_categories( intval( $post_ID ) );
     6558                $catids     = wp_get_post_categories( (int) $post_ID );
    65596559                // First listed category will be the primary category.
    65606560                $isPrimary = true;
     
    68136813                } elseif ( isset( $urltest['fragment'] ) ) {
    68146814                        // An #anchor is there, it's either...
    6815                         if ( intval( $urltest['fragment'] ) ) {
     6815                        if ( (int) $urltest['fragment'] ) {
    68166816                                // ...an integer #XXXX (simplest case),
    68176817                                $post_ID = (int) $urltest['fragment'];
Note: See TracChangeset for help on using the changeset viewer.