[wp-trac] [WordPress Trac] #42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284
    WordPress Trac 
    noreply at wordpress.org
       
    Sat Jun  1 16:46:59 UTC 2019
    
    
  
#42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284
-------------------------------------------------+-------------------------
 Reporter:  internetwerk                         |       Owner:
                                                 |  boonebgorges
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  5.2
Component:  Posts, Post Types                    |     Version:  4.5
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  dev-feedback has-patch 2nd-opinion   |     Focuses:
  php73 has-unit-tests                           |
-------------------------------------------------+-------------------------
Comment (by jcdev518):
 Replying to [comment:25 Kelderic]:
 > I just ran into this when I began testing with PHP 7.2. In my <head>
 section of my theme, I call `get_the_excerpt` as part of Open Graph meta
 tags. I have tried passing the post ID using `get_the_ID`, and passing
 `$post`, but I can't get rid of the error.
 >
 > If we add:
 >
 > {{{#!php
 > if ( ! is_array($pages) ) {
 >       $pages = [];
 > }
 > }}}
 >
 > At line 283 of post-template.php, we correct the issue. Long term, we
 need to check that all expected arrays are really arrays, and convert
 `NULL` values to empty arrays before calling `count()`.
 Re: ticket #42814
 I know this has been marked as "completed" but I ran into a similar issue
 with PHP 7.2 this many months later.
 Same error, but on line 310 of post-template.php after calling
 get_the_content() outside of the main loop. This is in a singular page
 template where $post is already global.
 Although it seemed redundant, I wrapped the call inside the loop:
 {{{#!php
 <?php
 while ( have_posts ):
   the_post();
   get_the_content();
 endwhile;
 }}}
 and it fixed the error, as it's no longer trying to count() a null value
 in {{{#!php
 {{{#!php
 $elements['pages'];
 }}}
 FYI this is now on WP 5.2.1 - thought I'd mention it as a way to fix
 without modifying core.
-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/42814#comment:108>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list