[wp-trac] [WordPress Trac] #50784: Stop using `preg_match()` in `wp_opcache_invalidate()`
WordPress Trac
noreply at wordpress.org
Mon Jul 27 20:31:18 UTC 2020
#50784: Stop using `preg_match()` in `wp_opcache_invalidate()`
------------------------------+---------------------
Reporter: mikeschroder | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.5
Component: Upgrade/Install | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch commit | Focuses:
------------------------------+---------------------
Comment (by desrosj):
Of the three approaches, I think I too prefer
[attachment:"50784.substr.diff"].
At first, another option that I thought of was using `strpos()` or
`stripos()`. In my testing, this was the most performant approach.
However, negative offsets are only supported in PHP >= 7.1
That would look like this:
`if ( false !== strpos( $filepath, '.php', -4 )`
Another option, though I'm not sure it's a readability improvement, is
using `in_array()` and `substr()`.
`if ( ! in_array( substr( $filepath, -4 ), array( '.php', '.PHP' ), true )
)`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50784#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list