[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> compat.php (summary)

WordPress implementation for PHP functions either missing from older PHP versions or not included by default.

File Size: 499 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 2 files
 wp-includes/random_compat/random.php
 wp-includes/sodium_compat/autoload.php

Defines 16 functions

  _()
  _wp_can_use_pcre_u()
  mb_substr()
  _mb_substr()
  mb_strlen()
  _mb_strlen()
  hash_hmac()
  _hash_hmac()
  hash_equals()
  is_countable()
  is_iterable()
  array_key_first()
  array_key_last()
  str_contains()
  str_starts_with()
  str_ends_with()

Functions
Functions that are not part of a class:

_( $message )   X-Ref
No description

_wp_can_use_pcre_u( $set = null )   X-Ref
Returns whether PCRE/u (PCRE_UTF8 modifier) is available for use.

since: 4.2.2
param: bool $set - Used for testing only

mb_substr( $string, $start, $length = null, $encoding = null )   X-Ref
Compat function to mimic mb_substr().

since: 3.2.0
param: string      $string   The string to extract the substring from.
param: int         $start    Position to being extraction from in `$string`.
param: int|null    $length   Optional. Maximum number of characters to extract from `$string`.
param: string|null $encoding Optional. Character encoding to use. Default null.
return: string Extracted substring.

_mb_substr( $str, $start, $length = null, $encoding = null )   X-Ref
Internal compat function to mimic mb_substr().

Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit.
For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte
sequence. The behavior of this function for invalid inputs is undefined.

since: 3.2.0
param: string      $str      The string to extract the substring from.
param: int         $start    Position to being extraction from in `$str`.
param: int|null    $length   Optional. Maximum number of characters to extract from `$str`.
param: string|null $encoding Optional. Character encoding to use. Default null.
return: string Extracted substring.

mb_strlen( $string, $encoding = null )   X-Ref
Compat function to mimic mb_strlen().

since: 4.2.0
param: string      $string   The string to retrieve the character length from.
param: string|null $encoding Optional. Character encoding to use. Default null.
return: int String length of `$string`.

_mb_strlen( $str, $encoding = null )   X-Ref
Internal compat function to mimic mb_strlen().

Only understands UTF-8 and 8bit.  All other character sets will be treated as 8bit.
For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte
sequence. The behavior of this function for invalid inputs is undefined.

since: 4.2.0
param: string      $str      The string to retrieve the character length from.
param: string|null $encoding Optional. Character encoding to use. Default null.
return: int String length of `$str`.

hash_hmac( $algo, $data, $key, $binary = false )   X-Ref
Compat function to mimic hash_hmac().

The Hash extension is bundled with PHP by default since PHP 5.1.2.
However, the extension may be explicitly disabled on select servers.
As of PHP 7.4.0, the Hash extension is a core PHP extension and can no
longer be disabled.
I.e. when PHP 7.4.0 becomes the minimum requirement, this polyfill
and the associated `_hash_hmac()` function can be safely removed.

since: 3.2.0
param: string $algo   Hash algorithm. Accepts 'md5' or 'sha1'.
param: string $data   Data to be hashed.
param: string $key    Secret key to use for generating the hash.
param: bool   $binary Optional. Whether to output raw binary data (true),
return: string|false The hash in output determined by `$binary`.

_hash_hmac( $algo, $data, $key, $binary = false )   X-Ref
Internal compat function to mimic hash_hmac().

since: 3.2.0
param: string $algo   Hash algorithm. Accepts 'md5' or 'sha1'.
param: string $data   Data to be hashed.
param: string $key    Secret key to use for generating the hash.
param: bool   $binary Optional. Whether to output raw binary data (true),
return: string|false The hash in output determined by `$binary`.

hash_equals( $known_string, $user_string )   X-Ref
Timing attack safe string comparison.

Compares two strings using the same time whether they're equal or not.

Note: It can leak the length of a string when arguments of differing length are supplied.

This function was added in PHP 5.6.
However, the Hash extension may be explicitly disabled on select servers.
As of PHP 7.4.0, the Hash extension is a core PHP extension and can no
longer be disabled.
I.e. when PHP 7.4.0 becomes the minimum requirement, this polyfill
can be safely removed.

since: 3.9.2
param: string $known_string Expected string.
param: string $user_string  Actual, user supplied, string.
return: bool Whether strings are equal.

is_countable( $value )   X-Ref
Polyfill for is_countable() function added in PHP 7.3.

Verify that the content of a variable is an array or an object
implementing the Countable interface.

since: 4.9.6
param: mixed $value The value to check.
return: bool True if `$value` is countable, false otherwise.

is_iterable( $value )   X-Ref
Polyfill for is_iterable() function added in PHP 7.1.

Verify that the content of a variable is an array or an object
implementing the Traversable interface.

since: 4.9.6
param: mixed $value The value to check.
return: bool True if `$value` is iterable, false otherwise.

array_key_first( array $array )   X-Ref
Polyfill for array_key_first() function added in PHP 7.3.

Get the first key of the given array without affecting
the internal array pointer.

since: 5.9.0
param: array $array An array.
return: string|int|null The first key of array if the array

array_key_last( array $array )   X-Ref
Polyfill for `array_key_last()` function added in PHP 7.3.

Get the last key of the given array without affecting the
internal array pointer.

since: 5.9.0
param: array $array An array.
return: string|int|null The last key of array if the array

str_contains( $haystack, $needle )   X-Ref
Polyfill for `str_contains()` function added in PHP 8.0.

Performs a case-sensitive check indicating if needle is
contained in haystack.

since: 5.9.0
param: string $haystack The string to search in.
param: string $needle   The substring to search for in the haystack.
return: bool True if `$needle` is in `$haystack`, otherwise false.

str_starts_with( $haystack, $needle )   X-Ref
Polyfill for `str_starts_with()` function added in PHP 8.0.

Performs a case-sensitive check indicating if
the haystack begins with needle.

since: 5.9.0
param: string $haystack The string to search in.
param: string $needle   The substring to search for in the `$haystack`.
return: bool True if `$haystack` starts with `$needle`, otherwise false.

str_ends_with( $haystack, $needle )   X-Ref
Polyfill for `str_ends_with()` function added in PHP 8.0.

Performs a case-sensitive check indicating if
the haystack ends with needle.

since: 5.9.0
param: string $haystack The string to search in.
param: string $needle   The substring to search for in the `$haystack`.
return: bool True if `$haystack` ends with `$needle`, otherwise false.



Generated: Sun May 29 01:00:02 2022 Cross-referenced by PHPXref 0.7.1