[wp-trac] [WordPress Trac] #21402: Remove PHP4 methods, format consistently
WordPress Trac
noreply at wordpress.org
Wed Jan 22 05:52:38 UTC 2020
#21402: Remove PHP4 methods, format consistently
-----------------------------+-----------------------------
Reporter: wonderboymusic | Owner: SergeyBiryukov
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 5.4
Component: Cache API | Version:
Severity: normal | Resolution:
Keywords: has-patch early | Focuses:
-----------------------------+-----------------------------
Changes (by SergeyBiryukov):
* keywords: has-patch needs-testing needs-unit-tests early => has-patch
early
Comment:
Replying to [comment:2 nacin]:
> 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.
In my testing, both seem to be the case.
* Since PHP 5.1, shutdown is called before the output buffer is implicitly
flushed by the termination of the script:[[BR]] https://3v4l.org/u4VR7
{{{
<?php
register_shutdown_function( 'shutdown_func' );
function ob_callback( $buffer ) {
$buffer .= __FUNCTION__ . ' ';
return $buffer;
}
function shutdown_func() {
echo __FUNCTION__ . ' ';
}
ob_start( 'ob_callback' );
?>
Output for 5.1.0 - 7.4.1
shutdown_func ob_callback
Output for 4.3.0 - 5.0.5
ob_callback shutdown_func
}}}
* Since PHP 5.2, objects are destroyed before the output buffer is flushed
by the termination of the script:[[BR]] https://3v4l.org/eO8t0
{{{
<?php
class foo {
function bar() {
}
}
$GLOBALS['fb'] = new foo;
function foo_bar( $buffer ) {
$buffer .= "gettype( 'fb' ): " . gettype( $GLOBALS['fb'] );
return $buffer;
}
ob_start( 'foo_bar' );
?>
Output for 5.2.0 - 7.4.1
gettype( 'fb' ): NULL
Output for 4.3.0 - 5.1.6
gettype( 'fb' ): object
}}}
* Our fiddling with the destructor does not exactly help. Interestingly,
it only works on PHP 7.0.6+:[[BR]] https://3v4l.org/L4O6I
{{{
<?php
class foo {
function __construct() {
register_shutdown_function( array( $this, '__destruct' )
);
}
function bar() {
}
function __destruct() {
return true;
}
}
$GLOBALS['fb'] = new foo;
function foo_bar( $buffer ) {
$buffer .= "gettype( 'fb' ): " . gettype( $GLOBALS['fb'] );
return $buffer;
}
ob_start( 'foo_bar' );
?>
Output for 4.3.0 - 5.1.6, 7.0.6 - 7.4.1
gettype( 'fb' ): object
Output for 5.2.0 - 7.0.5
gettype( 'fb' ): NULL
}}}
* On the other hand, explicitly flushing the buffer on shutdown works on
PHP 5.1+ and all later versions:[[BR]] https://3v4l.org/m8rAm
{{{
<?php
register_shutdown_function( 'ob_end_flush' );
class foo {
function bar() {
}
}
$GLOBALS['fb'] = new foo;
function foo_bar( $buffer ) {
$buffer .= "gettype( 'fb' ): " . gettype( $GLOBALS['fb'] );
return $buffer;
}
ob_start( 'foo_bar' );
?>
Output for 5.1.0 - 7.4.1
gettype( 'fb' ): object
}}}
The discussion on #3354, starting from comment:32:ticket:3354, appears to
corroborate these results.
To summarize, [5462] was the real fix here, not [4686].
[attachment:"21402.2.diff"] should be good to go.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/21402#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list