[wp-trac] [WordPress Trac] #42761: Undefined offset: -1 in wp-includes/post-template.php

WordPress Trac noreply at wordpress.org
Thu Nov 30 18:37:35 UTC 2017


#42761: Undefined offset: -1 in wp-includes/post-template.php
--------------------------+-----------------------------
 Reporter:  twisted1919   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.9.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 I am getting this notice:

 <b>Notice</b>:  Undefined offset: -1 in
 <b>/var/www/vhosts/domain/httpdocs/web/wp-includes/post-template.php</b>
 on line <b>287</b><br />

 The logic that checks for index presence is faulty:
 {{{#!php
 <?php
 if ( $page > count( $pages ) ) // if the requested page doesn't exist
                 $page = count( $pages ); // give them the highest numbered
 page that DOES exist
 }}}

 If `$page` is 0 or 1 and `$pages` is an empty array, you end up checking
 an out of bounds array and trigger this notice.

 Maybe a more complete fix would be:
 {{{#!php
 <?php
 if ( $page > count( $pages ) ) // if the requested page doesn't exist
                 $page = count( $pages ); // give them the highest numbered
 page that DOES exist

         $content = isset($pages[$page - 1]) ? $pages[$page - 1] : '';
 }}}
 Ow whatever you think it will avoid this.

 Thanks.

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


More information about the wp-trac mailing list