[wp-trac] [WordPress Trac] #40397: PHP 7.1.x problem in WP_Query
WordPress Trac
noreply at wordpress.org
Sun Apr 9 19:02:33 UTC 2017
#40397: PHP 7.1.x problem in WP_Query
--------------------------+------------------------------
Reporter: dglingren | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 4.7.3
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by dglingren):
Thanks, @SergeyBiryukov, for your response. Removing the ampersand avoids
the PHP message but I do not believe it solves the problem. The original
call on line 1995 of class-wp-query.php reads:
`$search = apply_filters_ref_array( 'posts_search', array( $search, &$this
) );`
It looks like the WP_Query object is being passed to the filter by
reference, not by value, so the filter can modify elements such as the
query_vars array. The Codex documentation for apply_filters_ref_array
includes:
"As of PHP 5.4, the array is no longer passed by reference despite the
function's name. You cannot even use the reference sign '&' because call
time pass by reference now throws an error. What you can do is pass the
reference pointer as an array element. Doing so does require all callbacks
added to the filter to expect a reference pointer. This is not something
you will see in WordPress actions. This technique is provided for
informational purposes only.
{{{
apply_filters_ref_array( 'my_filter', array( &$args ));
add_action('my_filter', 'my_callback');
function my_callback( &$args ) {
//access values with $args[0], $args[1] etc.
}
}}}
Because the original array was passed by reference, any changes to the
array elements are applied to the original array outside of the function's
scope."
You can see the ampersand in `my_callback`; removing it defeats one
purpose of the filter. Am I just confused?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40397#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list