WordPress.org

Make WordPress Core

Ticket #50767: 50767-use-instanceof.patch

File 50767-use-instanceof.patch, 3.1 KB (added by jrf, 11 months ago)

Modernize: use instanceof instead of a comparison with get_class() Includes adjusting external libraries which are no longer maintained externally.

  • src/wp-admin/includes/class-pclzip.php

    From a1716dc9bead3c205890339986e4090ae22f72bd Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sun, 18 Oct 2020 08:27:46 +0200
    Subject: [PATCH] Modernize: use `instanceof` instead of a comparison with
     `get_class()`
    
    Includes adjusting external libraries which are no longer maintained externally.
    ---
     src/wp-admin/includes/class-pclzip.php | 4 ++--
     src/wp-includes/Text/Diff.php          | 2 +-
     src/wp-includes/class-json.php         | 2 +-
     src/wp-includes/rest-api.php           | 2 +-
     4 files changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/src/wp-admin/includes/class-pclzip.php b/src/wp-admin/includes/class-pclzip.php
    index 47f2a344a2..3757497d6c 100644
    a b  
    11711171    $this->privErrorReset();
    11721172
    11731173    // ----- Look if the $p_archive is a PclZip object
    1174     if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
     1174    if ((is_object($p_archive)) && $p_archive instanceof pclzip)
    11751175    {
    11761176
    11771177      // ----- Duplicate the archive
     
    12351235    }
    12361236
    12371237    // ----- Look if the $p_archive_to_add is a PclZip object
    1238     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
     1238    if ((is_object($p_archive_to_add)) && $p_archive_to_add instanceof pclzip)
    12391239    {
    12401240
    12411241      // ----- Merge the archive
  • src/wp-includes/Text/Diff.php

    diff --git a/src/wp-includes/Text/Diff.php b/src/wp-includes/Text/Diff.php
    index ab1c9a26dd..61a9320a0e 100644
    a b class Text_Diff { 
    276276
    277277        $prevtype = null;
    278278        foreach ($this->_edits as $edit) {
    279             if ($prevtype == get_class($edit)) {
     279            if ($edit instanceof $prevtype) {
    280280                trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
    281281            }
    282282            $prevtype = get_class($edit);
  • src/wp-includes/class-json.php

    diff --git a/src/wp-includes/class-json.php b/src/wp-includes/class-json.php
    index 66443e1068..036150f1d8 100644
    a b class Services_JSON 
    918918
    919919        if (class_exists('pear')) {
    920920            return PEAR::isError($data, $code);
    921         } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
     921        } elseif (is_object($data) && ($data instanceof services_json_error ||
    922922                                 is_subclass_of($data, 'services_json_error'))) {
    923923            return true;
    924924        }
  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index bbbeae3532..ed62943309 100644
    a b function rest_get_route_for_term( $term ) { 
    23902390        $route = '';
    23912391
    23922392        // The only controller that works is the Terms controller.
    2393         if ( 'WP_REST_Terms_Controller' === get_class( $controller ) ) {
     2393        if ( $controller instanceof WP_REST_Terms_Controller ) {
    23942394                $namespace = 'wp/v2';
    23952395                $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
    23962396                $route     = sprintf( '/%s/%s/%d', $namespace, $rest_base, $term->term_id );