[wp-trac] [WordPress Trac] #20756: Wrong reference returned in function &get_pages

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 13 14:36:39 UTC 2012


#20756: Wrong reference returned in function &get_pages
------------------------------+------------------------
 Reporter:  thomask           |       Owner:  foxinni
     Type:  defect (bug)      |      Status:  reviewing
 Priority:  normal            |   Milestone:  3.5
Component:  Warnings/Notices  |     Version:  3.3.2
 Severity:  trivial           |  Resolution:
 Keywords:  has-patch         |
------------------------------+------------------------

Comment (by wonderboymusic):

 The function needs to continue to return its result by reference. The two
 places it contain return {{{false}}} should return a variable. By setting
 {{{$pages}}} to {{{false}}} at the top of the function, we can just return
 {{{$pages}}} instead of {{{false}}}.

 For those who don't understand what is going on:[[BR]]
 http://www.php.net/manual/en/language.references.return.php

 When you "return by reference," you have to actually return a variable:
 {{{
 // returns by reference
 function &get_pages( $args ) { return $pages; }

 // $my_var becomes a symbol table alias for $pages
 $my_var = get_pages();
 }}}

 The only other way to make $my_var a reference everywhere:
 {{{
 $my_var =& get_pages();
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20756#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list