Make WordPress Core


Ignore:
Timestamp:
05/07/2023 11:42:18 AM (21 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Bring more consistency to PHP 8.0 string function polyfills.

This adjusts str_contains() code layout to have an early exit for an empty $needle, matching similar fragments in str_starts_with() and str_ends_with() for better readability.

Follow-up to [52039], [52040].

See #57839.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/compat.php

    r55136 r55726  
    435435     *
    436436     * @param string $haystack The string to search in.
    437      * @param string $needle   The substring to search for in the haystack.
     437     * @param string $needle   The substring to search for in the `$haystack`.
    438438     * @return bool True if `$needle` is in `$haystack`, otherwise false.
    439439     */
    440440    function str_contains( $haystack, $needle ) {
    441         return ( '' === $needle || false !== strpos( $haystack, $needle ) );
     441        if ( '' === $needle ) {
     442            return true;
     443        }
     444
     445        return false !== strpos( $haystack, $needle );
    442446    }
    443447}
Note: See TracChangeset for help on using the changeset viewer.