Make WordPress Core

Changeset 59583


Ignore:
Timestamp:
01/07/2025 03:40:19 PM (13 days ago)
Author:
desrosj
Message:

Tests: Fix explode() error for old DB versions on PHP 8.1+.

On MySQL/MariaDB 5.5, the default value for sql_mode was a blank string. By itself this is not a problem. However, $wpdb->get_var() returns null when a variable has an empty value.

One test method currently passes the result of $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' ) to explode() in order to reset the database to the pre-test method state. This causes an error when running PHP 8.1+, which deprecated the ability to pass null as a parameter of explode().

This edge case was undiscovered because these versions are not currently included in the automated testing matrix.

See #62280.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db.php

    r59069 r59583  
    297297        $this->assertSameSets( $new_modes, explode( ',', $check_new_modes ) );
    298298
    299         $wpdb->set_sql_mode( explode( ',', $current_modes ) );
     299        $wpdb->set_sql_mode( empty( $current_modes ) ? array() : explode( ',', $current_modes ) );
    300300    }
    301301
Note: See TracChangeset for help on using the changeset viewer.