[wp-trac] [WordPress Trac] #42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284

WordPress Trac noreply at wordpress.org
Thu Mar 28 15:46:07 UTC 2019


#42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284
-------------------------------------------------+-------------------------
 Reporter:  internetwerk                         |       Owner:
                                                 |  boonebgorges
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  5.2
Component:  Posts, Post Types                    |     Version:  4.5
 Severity:  normal                               |  Resolution:
 Keywords:  dev-feedback has-patch 2nd-opinion   |     Focuses:
  php73 has-unit-tests                           |
-------------------------------------------------+-------------------------
Changes (by david.binda):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 Testing the r44941 on some in-house and client's code on WordPress.com, I
 run into issues with certain implementations.

 To be honest, the sample failing code does not feel right, but it has been
 working up until applying the r44941.

 Here is an example failing implementation in a form of a unit test:

 {{{#!php
 <?php
     public function
 test_get_the_excerpt_after_setup_postdata_without_global_post() {
         $p1 = self::factory()->post->create_and_get(
             array(
                 'post_content' => 'Foo',
             )
         );

         $post_object = get_post( $p1->ID );
         setup_postdata( $post_object );

         $this->assertSame( 'Foo', get_the_content() );
     }
 }}}

 You might have noticed, that in order to make the code working properly,
 it either needs to override the global `$post` with `$post_object`, or
 pass the `$post_object` to the `get_the_content` function (taking
 advantage of the new param of the function).

 From my experience, forgetting to set the `global $post` value to whatever
 post is being processed inside a loop, or forgetting to call
 `setup_postdata` in there is quite common, and possibly easily overlooked,
 as call like `get_the_content()` simply works (despite the issues
 described in this ticket).

 I've run into several pieces of code which were refactored the way the
 `global $post` overriding was removed or broken, w/o failing the rest of
 the implementation until the r44941.

 It feels like this changeset has a capability of breaking some existing
 code leading to content not being displayed, which is unfortunate. Is
 there any chance to rethink the approach, or are we okay with this
 backward compatibility breaking change?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/42814#comment:100>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list