[wp-trac] [WordPress Trac] #41079: PHP Notice: Undefined offset: -1 in /var/www/html/live/wp-includes/rewrite.php

WordPress Trac noreply at wordpress.org
Mon Apr 8 06:14:36 UTC 2024


#41079: PHP Notice: Undefined offset: -1 in /var/www/html/live/wp-
includes/rewrite.php
---------------------------+------------------------------
 Reporter:  myrmidon16     |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Rewrite Rules  |     Version:  4.3
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by boceksumuklu):

 It seems like you've deduced that $postname_index is likely 0, which is
 causing the issue with the offsets of -1 at lines 376 and 378. If
 $postname_index is indeed 0, it would mean that the slug being checked is
 at the first position in the array.

 Given this context, your proposed solution of adding an additional
 condition to skip the scenario when $postname_index is 0 seems
 appropriate:

 {{{#!php
 if ( 0 === $postname_index || in_array( $slug_index,
 $check_existing_slugs, true ) ) {
     // Skip the problematic scenario when $postname_index is 0
     // Other existing conditions and code here...
 }
 }}}


 By adding 0 === $postname_index to the if statement, you're ensuring that
 the block of code is skipped when $postname_index is 0. This should
 prevent the offsets of -1 from causing any issues.

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


More information about the wp-trac mailing list