mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-11 02:49:04 +01:00
WPDB: Check that $wpdb->last_result
is countable before counting with it.
`wpdb::get_col()` iterates over `$wpdb->last_result`, which can be a non-countable value, should the preceding query have failed. Props spacedmonkey, desrosj, pento. Merges [43934] into trunk. See #45299. Built from https://develop.svn.wordpress.org/trunk@44272 git-svn-id: http://core.svn.wordpress.org/trunk@44102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
820f643bff
commit
945ba795dc
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.1-alpha-44271';
|
$wp_version = '5.1-alpha-44272';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
@ -2544,8 +2544,10 @@ class wpdb {
|
|||||||
|
|
||||||
$new_array = array();
|
$new_array = array();
|
||||||
// Extract the column values
|
// Extract the column values
|
||||||
for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
|
if ( $this->last_result ) {
|
||||||
$new_array[ $i ] = $this->get_var( null, $x, $i );
|
for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
|
||||||
|
$new_array[ $i ] = $this->get_var( null, $x, $i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $new_array;
|
return $new_array;
|
||||||
}
|
}
|
||||||
@ -2585,11 +2587,13 @@ class wpdb {
|
|||||||
} elseif ( $output == OBJECT_K ) {
|
} elseif ( $output == OBJECT_K ) {
|
||||||
// Return an array of row objects with keys from column 1
|
// Return an array of row objects with keys from column 1
|
||||||
// (Duplicates are discarded)
|
// (Duplicates are discarded)
|
||||||
foreach ( $this->last_result as $row ) {
|
if ( $this->last_result ) {
|
||||||
$var_by_ref = get_object_vars( $row );
|
foreach ( $this->last_result as $row ) {
|
||||||
$key = array_shift( $var_by_ref );
|
$var_by_ref = get_object_vars( $row );
|
||||||
if ( ! isset( $new_array[ $key ] ) ) {
|
$key = array_shift( $var_by_ref );
|
||||||
$new_array[ $key ] = $row;
|
if ( ! isset( $new_array[ $key ] ) ) {
|
||||||
|
$new_array[ $key ] = $row;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $new_array;
|
return $new_array;
|
||||||
|
Loading…
Reference in New Issue
Block a user