[wp-trac] [WordPress Trac] #48312: PHP4 notation for passing object by reference broken

WordPress Trac noreply at wordpress.org
Tue Oct 15 17:59:48 UTC 2019


#48312: PHP4 notation for passing object by reference broken
--------------------------+-----------------------------
 Reporter:  david.binda   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 This is quite weird situation, since WordPress has already dropped support
 for PHP < 5.6.20, the r46149 is removing support for PHP 4 way of passing
 in object as references:

 {{{#!php
 if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) &&
 is_object( $arg[0] ) ) { // array(&$this) {
     $args[] =& $arg[0];
 }
 }}}

 which may be breaking code, which works in PHP4 and due to the compat
 logic in do_action ( introduced in r4177 ), still works nowadays. Eg.:

 {{{#!php
 do_action( 'some_action', array( $this ) );
 }}}

 It's true that in PHP 5 all objects are being passed as references, so the
 array wrapping is no longer needed, but in case there is a code using the
 old notation (see above), the args are not really being passed to the
 callback in an expected way, eventually producing issues in the callbacks.

 I'm attaching a phpunit test simulating the faulty behaviour, which was/is
 working before r46149.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48312>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list