Mantis - Quercus
Viewing Issue Advanced Details
4620 minor always 06-16-11 08:56 03-12-13 12:22
thr  
nam  
normal  
closed 4.0.14  
unable to reproduce  
none    
none  
0004620: Quercus passes 'by value object' as 'reference'
Setting up Wordpress 3.1.3 on Quercus after making some quirks to get it run (Issue 0004568 and Issue 0004612) I get it working. Only if I signed in as admin and Under the menu Item where all articels are listed, I found a difference to a 'normal' php wordpress installation. All the links below the artikel list, which will allow you to edit, delete, etc, the articels, all my links where gone, like I do not have permission to edit.

Investigating the problem I found that Wordpress is using a function called 'wp_list_pluck' to reduce a big array of article-type definitions to a single value.

Thru some calls Wordpress passed the object $wp_post_types to this function.
This function then returns one field out of this object.
As this list is assigning a new value to one of the function parameters and returning it to the callee, I found after thre calls the original $wp_post_types was modfied/damaged.
As php is passing the object by value, this should not be possible. Under some circumstances Quercus seems to pass this object as reference.

To fix this, I changed the funtion in Wordpress to use a new variable to return the result instead of the function parameter.

Unfortunately I could not simulate the behaviour in a simple test script. But anyway I might want to have a look to understand the principle problem ...
 but there must be happening more in wordpress to cause this .....

/**
 * Pluck a certain field out of each object in a list
 *
 * @since 3.1.0
 *
 * @param array $list A list of objects or arrays
 * @param int|string $field A field from the object to place instead of the entire object
 * @return array
 */
function wp_list_pluck( $list, $field ) {
    foreach ( $list as $key => $value ) {
        $value = (array) $value;
        $list[ $key ] = $value[ $field ];
    }

    return $list;
}

CHANEGED To:

function wp_list_pluck( $list, $field ) {
    foreach ( $list as $key => $value ) {
        $value = (array) $value;
        $new_list[ $key ] = $value[ $field ];
    }

    return $new_list;
}
 test_array_ref.php [^] (11,500 bytes) 06-16-11 08:56

Notes
(0005684)
krystian   
01-30-12 11:35   
I can also confirm it is still the case in Resin 4.0.24
(0006130)
nam   
12-30-12 00:13   
Unable to reproduce in 4.0.33. Tried wordpress-3.1.3, wordpress-3.5, and your attached script.

We did fix a few value-vs-reference issues starting over the course of the last 6 months.