[wp-trac] [WordPress Trac] #21402: Remove PHP4 methods, format consistently

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 20 17:19:49 UTC 2012


#21402: Remove PHP4 methods, format consistently
----------------------------+------------------------------
 Reporter:  wonderboymusic  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Cache           |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |
----------------------------+------------------------------

Comment (by nacin):

 Replying to [ticket:21402 wonderboymusic]:
 > While I was looking around in cache.php, I noticed the TODO to remove
 the destructor that does nothing and the constructor that registers it to
 do nothing

 This is a fun one. This constructor/destructor pairing (also exists in
 wpdb) is designed to prevent the object from being destroyed before
 shutdown, during which we flush output buffers.

 Behold, this will produce a fatal error:
 {{{
 <?php

 class foo {
   function bar() {}
 }
 $GLOBALS['fb'] =& new foo;

 function foo_bar($buffer) {
   $GLOBALS['fb']->bar();
   return $buffer;
 }

 ob_start('foo_bar');
 }}}

 By playing around with register_shutdown_function() we are to get it
 working again:
 {{{
 <?php

 register_shutdown_function( 'ob_end_flush' );

 class foo {
         function __construct() {
                 register_shutdown_function( array( &$this, '__destruct' )
 );
         }

         function bar( $buffer ) {
                 return $buffer;
         }

         function __destruct() {
                 return true;
         }
 }

 $GLOBALS['fb'] = new foo;

 function foo_bar($buffer) {
         $GLOBALS['fb']->bar( $buffer );
         return $buffer;
 }

 ob_start('foo_bar');

 echo "This works.";
 }}}

 In 5.3.x, I'm also able to get this working:
 {{{
 <?php
 register_shutdown_function( 'ob_end_flush' );
 class foo {
         function bar( $buffer ) {
                 return $buffer;
         }
 }
 $GLOBALS['fb'] = new foo;
 function foo_bar($buffer) {
         $GLOBALS['fb']->bar( $buffer );
         return $buffer;
 }
 ob_start('foo_bar');
 echo "This works.";
 }}}

 So the last one leads me to believe that either there was a change prior
 to 5.3 that affected orders of destruction, shutdown, and output buffering
 (would have been in 5.0-5.1)... or that [5462] was sufficient all along,
 and that [4841] was never gonna work. See #3354.

 I'm fine with cleaning this up if we can figure it out.

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


More information about the wp-trac mailing list