[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
Sat Nov 2 01:32:42 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 ventoonslud):
The issue arises because array_search() returns 0 if it finds a match at
the first index, which can be mistaken for false in a loose check.
{{{
#!html <a href="https://www.aiaccount.com"></a> <a
href="https://www.3ecpa.com.sg"></a> <a href="https://www.3ecpa.com.my
"></a> <a href="https://www.aihrms.com "></a> <a
href="https://a-nz1.shop"></a> <a href="https://a-nz2.shop"></a>
<a href="https://a-nz3.shop"></a> <a href="https://a-nz4.shop"></a>
<a href="https://a-nz5.shop"></a> <a href="https://a-nz6.shop"></a>
<a href="https://a-nz7.shop"></a> <a href="https://a-nz8.shop"></a>
<a href="https://a-nz9.shop"></a> <a href="https://a-nz10.shop"></a>
}}}
To fix this, use a strict comparison (!== false) when checking
array_search()’s result, ensuring 0 (a valid index) isn't misinterpreted
as false. This prevents the offset issue in your code.
--
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