WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#39075 closed defect (bug) (invalid)

wpdb return type constants broken in 4.7 RC2 - always returns ARRAY_N

Reported by: sterndata Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Query Keywords:
Focuses: Cc:
PR Number:

Description

Given this code:

<?php
<?php

include_once( 'wp-load.php' );

$query = 'select `ID` from sds_wp_posts LIMIT 0,2';

echo "OBJECT";

$result = $wpdb->get_results( $query, OBJECT );

echo '<pre>';
print_r( $result );
echo '</pre>';


echo "ARRAY_A";

$result = $wpdb->get_results( $query, ARRAY_A );

echo '<pre>';
print_r( $result );
echo '</pre>';


echo "ARRAY_N";

$result = $wpdb->get_results( $query, ARRAY_N );

echo '<pre>';
print_r( $result );
echo '</pre>';

Result are OK in 4.6.1

OBJECT
Array
(
    [0] => stdClass Object
        (
            [ID] => 1
        )

    [1] => stdClass Object
        (
            [ID] => 2
        )

)
ARRAY_A
Array
(
    [0] => Array
        (
            [ID] => 1
        )

    [1] => Array
        (
            [ID] => 2
        )

)
ARRAY_N
Array
(
    [0] => Array
        (
            [0] => 1
        )

    [1] => Array
        (
            [0] => 2
        )

)

but incorrect in 4.7 RC2

OBJECT
Array
(
    [0] => stdClass Object
        (
            [ID] => 6
        )

    [1] => stdClass Object
        (
            [ID] => 8
        )

)
ARRAY_A
Array
(
    [0] => Array
        (
            [ID] => 6
        )

    [1] => Array
        (
            [ID] => 8
        )

)
ARRAY_N
Array
(
    [0] => Array
        (
            [0] => 6
        )

    [1] => Array
        (
            [0] => 8
        )

)

Change History (9)

#1 @sterndata
3 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Correction: I mis-pasted. The first example should be the correct ouptput:

OBJECT
Array
(

[0] => stdClass Object

(

[ID] => 1

)

[1] => stdClass Object

(

[ID] => 2

)

)
ARRAY_A
Array
(

[0] => Array

(

[ID] => 1

)

[1] => Array

(

[ID] => 2

)

)
ARRAY_N
Array
(

[0] => Array

(

[0] => 1

)

[1] => Array

(

[0] => 2

)

)

#2 @swissspidy
3 years ago

  • Keywords reporter-feedback added
  • Resolution invalid deleted
  • Status changed from closed to reopened

Seems like the ticket was closed accidentally.

@sterndata Can you give use some more information, perhaps in form of unit tests? What version of PHP are you using?

#3 @swissspidy
3 years ago

  • Component changed from Query to Database

#4 @sterndata
3 years ago

  • Component changed from Database to Query
  • Resolution set to invalid
  • Status changed from reopened to closed

Please ignore this ticket. I misread things.

#5 @swissspidy
3 years ago

#39086 was marked as a duplicate.

#6 @prodev
3 years ago

Hi pals,

Thought this one was deleted yesterday, sterndata was supposed to repost it or something, anyway, this has to be fixed as soon as possible, I don't have a unit test, just try the sample sterndata has provided, it's always ARRAY_N (ignore the 2nd output sample).

Last edited 3 years ago by prodev (previous) (diff)

#7 @sterndata
3 years ago

the output is identical on 4.6 and 4.7RC2 -- I was wrong.

http://devbase.sterndata.com/test.php (4.6)
https://www.stevenstern.me/test.php (4.7 RC2)

#8 @prodev
3 years ago

I can confirm that but what happened, anyway, I'm glad it's working!

Last edited 3 years ago by prodev (previous) (diff)

#9 @netweb
3 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.