usephul
Table of Contents
Namespaces
Enums
- Type
- Possible types as returned by {@see gettype()}.
Constants
- E_EVERYTHING = 0x7fffffff
- This mask matches every possible past and future PHP error level.
- PHP_ZERO_TOLERANCE = 9.999999999999999E-12
- Default error tolerance.
Functions
- array_remap() : array<string|int, mixed>
- Applies a (generator) callback to the elements of a given array, allowing the remapping of its keys in the process.
- array_zip() : array<string|int, array<string|int, TValue>>
- Perform a zip operation on multiple arrays.
- filename() : string
- Returns the name component of path without the extension.
- extension() : string
- Returns the extension component of path without the extension.
- array_interchange() : array<string|int, mixed>
- Interchange the values of two elements of an array.
- is_closed_resource() : mixed
- Finds whether the given variable is a {@link https://www.php.net/types.resource resource} that has been closed.
- is_zero() : bool
- Finds whether the given number is (sufficiently close to) 0.
- seq() : Generator<string|int, string|int>
- Sequences a value into a {@see \Generator}.
- uses() : bool
- Checks whether an object or class uses a given trait.
- class_parents_uses() : array<class-string, class-string>|false
- Return the traits used by the parent classes of the given class.
- class_parents_traits_uses() : array<class-string, class-string>|false
- Return the traits used by the parent classes of the given class, recursively.
- class_traits_uses() : array<class-string, class-string>|false
- Return the traits used by the given class or trait, recursively.
Constants
E_EVERYTHING
This mask matches every possible past and future PHP error level.
public
mixed
E_EVERYTHING
= 0x7fffffff
PHP_ZERO_TOLERANCE
Default error tolerance.
public
mixed
PHP_ZERO_TOLERANCE
= 9.999999999999999E-12
Functions
array_remap()
Applies a (generator) callback to the elements of a given array, allowing the remapping of its keys in the process.
array_remap(callable(TKey $key, TValue $value): mixed $callback, iterable<string|int, mixed> $array) : array<string|int, mixed>
array_remap() returns an array containing the results of applying a callback with the corresponding key and value of array used as arguments.
If callback is a generator function,
then it's possible to provide a new key for the resulting array element using
yield from $key => $value
.
If the same key is yielded more than once, then the later yield will override the previous one.
Parameters
- $callback : callable(TKey $key, TValue $value): mixed
-
A callable to run for each key-value pair in the array.
- $array : iterable<string|int, mixed>
Return values
array<string|int, mixed> —Returns an array containing the results of applying the callback function to the corresponding key-value pair of array used as arguments for the callback.
array_zip()
Perform a zip operation on multiple arrays.
array_zip(array<string|int, TValue> $array, array<string|int, TValue> ...$arrays) : array<string|int, array<string|int, TValue>>
Parameters
- $array : array<string|int, TValue>
-
An array to zip.
- $arrays : array<string|int, TValue>
-
Supplementary list of array arguments to zip.
Return values
array<string|int, array<string|int, TValue>> —Returns an array whose elements are each an array holding the elements of the input arrays of the same index.
filename()
Returns the name component of path without the extension.
filename(string $path[, string $suffix = '' ]) : string
Given a string containing the path to a file or directory, this function will return the trailing name component without the extension.
Note:
If the path has more than one extension, filename() only strips the last one.
Note:
filename() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".
Caution filename() is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale() function.
See Also
- dirname() - Returns a parent directory's path
- basename() - Returns trailing name component of path
- extension() - Returns extension component of path
- pathinfo() - Returns information about a file path
Parameters
- $path : string
-
A path.
- $suffix : string = ''
-
If the name component ends in suffix this will also be cut off.
Return values
stringextension()
Returns the extension component of path without the extension.
extension(string $path) : string
Given a string containing the path to a file or directory, this function will return the extension component.
Note:
If the path has more than one extension extension() returns only the last one.
Note:
extension() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".
Caution extension() is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale() function.
See Also
- dirname() - Returns a parent directory's path
- basename() - Returns trailing name component of path
- filename() - Returns basename of path, without extension
- pathinfo() - Returns information about a file path
Parameters
- $path : string
-
A path.
Return values
stringarray_interchange()
Interchange the values of two elements of an array.
array_interchange(array<string|int, mixed> $array, TKey $key1, TKey $key2) : array<string|int, mixed>
If a key doesn't exist in the array, then the other key will be set
to null
, and a warning will be thrown.
Parameters
- $array : array<string|int, mixed>
- $key1 : TKey
- $key2 : TKey
Return values
array<string|int, mixed>is_closed_resource()
Finds whether the given variable is a {@link https://www.php.net/types.resource resource} that has been closed.
is_closed_resource(T $value) : mixed
Parameters
- $value : T
-
The variable being evaluated.
Return values
mixed —Returns true
if value is a
resource variable that has been
closed, false
otherwise.
is_zero()
Finds whether the given number is (sufficiently close to) 0.
is_zero(int|float $value[, float|null $tolerance = PHP_ZERO_TOLERANCE ]) : bool
Parameters
- $value : int|float
-
The number being evaluated.
- $tolerance : float|null = PHP_ZERO_TOLERANCE
-
Tolerance allowed when evaluating the number.
Return values
bool —Returns true if value is (sufficiently close to) 0, false otherwise.
seq()
Sequences a value into a {@see \Generator}.
seq(mixed $value) : Generator<string|int, string|int>
Parameters
- $value : mixed
-
The value to sequence.
Return values
Generator<string|int, string|int>uses()
Checks whether an object or class uses a given trait.
uses(object|string $object_or_class, string $trait[, bool $allow_string = true ]) : bool
Parameters
- $object_or_class : object|string
-
A class name or an object instance.
- $trait : string
-
The trait name.
- $allow_string : bool = true
-
If this parameter set to false, string class name as object_or_class is not allowed. This also prevents from calling autoloader if the class doesn't exist.
Return values
bool —This function returns true if the object_or_class, or any of its traits, uses trait or if any of its parents, or its parents' traits, use trait.
class_parents_uses()
Return the traits used by the parent classes of the given class.
class_parents_uses(object|string $object_or_class[, bool $autoload = true ]) : array<class-string, class-string>|false
This function returns an array with the names of the traits that the parents of the given object_or_class use.
Parameters
- $object_or_class : object|string
-
An object or class name.
- $autoload : bool = true
-
Whether to autoload if not already loaded.
Return values
array<class-string, class-string>|false —An array on success, or false when the class doesn't exist.
class_parents_traits_uses()
Return the traits used by the parent classes of the given class, recursively.
class_parents_traits_uses(object|string $object_or_class[, bool $autoload = true ]) : array<class-string, class-string>|false
This function returns an array with the names of the traits that the parent classes of the given object_or_class uses, including traits used within those traits.
Parameters
- $object_or_class : object|string
-
An object or class name.
- $autoload : bool = true
-
Whether to autoload if not already loaded.
Return values
array<class-string, class-string>|false —An array on success, or false when the class doesn't exist.
class_traits_uses()
Return the traits used by the given class or trait, recursively.
class_traits_uses(object|string $object_or_class[, bool $autoload = true ]) : array<class-string, class-string>|false
This function returns an array with the names of the traits that the given object_or_class uses, including traits used by those traits, recursively. This does however not include any traits used by a parent class.
Parameters
- $object_or_class : object|string
-
An object, class name or trait name.
- $autoload : bool = true
-
Whether to autoload if not already loaded.
Return values
array<class-string, class-string>|false —An array on success, or false when the class doesn't exist.