Opened 22 months ago
Last modified 11 months ago
#57401 new defect (bug)
post-template.php fails to check if $elements['page'] is zero causing an array index error
Reported by: | mjdewitt | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Change History (3)
#2
@
12 months ago
I see this with WP 6.3.2 / PHP 8.1.24. In my case, the line number referred to in the error message is 330. The relevant lines (329/330) are
<?php $page_no = $elements['page']; $content = $elements['pages'][ $page_no - 1 ];
The problem is that $page_no can evaluate to 0, yielding an invalid negative index on line 330. I fixed this be replacing line 330 with
<?php if ( $page_no > 0 ) { $content = $elements['pages'][ $page_no - 1 ]; } else { $content = $elements['pages'][ 0 ]; }
With this, the error is gone. I suspect that this is linked to PHP > 8.0
Note: See
TracTickets for help on using
tickets.
Apologies, the code got mangled when posted.