Is

Boolean type and value tests: static functions that each take a value and return whether it is a string, number, id, email, url, date, array and more, with no side effects.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes
  • Is - boolean tests for the type or form of a value.

Is

The main class: static functions that each test a value and return a boolean, listed alphabetically.

Arr

Is::Arr($value, $optionalCheckCallback = null)

Whether the value is an array, and optionally that every item passes the given check callback.

NameTypeDescription
$valueThe value to test.
$optionalCheckCallbackA callable applied to each item; every item must pass. Null to skip the per-item check.

Returns bool True when the value is an array and every item passes any callback.

ArrayOfNum

Is::ArrayOfNum($value): bool

Whether the value is an array in which every item is a number.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is an array of numbers.

ArrayOfStr

Is::ArrayOfStr($value): bool

Whether the value is an array in which every item is a string.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is an array of strings.

Callback

Is::Callback($callback)

Whether the value is callable.

NameTypeDescription
$callbackThe value to test.

Returns bool True when the value can be called.

DatabaseName

Is::DatabaseName($value)

Whether the value is already a valid database name, unchanged by To::DatabaseName.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid database name.

Date

Is::Date($date)

Whether the value is a valid date, unchanged when converted by To::Date.

NameTypeDescription
$dateThe value to test.

Returns bool True when the value is a valid date.

DateOrNull

Is::DateOrNull($date)

Whether the value is null or a valid date.

NameTypeDescription
$dateThe value to test.

Returns bool True when the value is null or a valid date.

DomainName

Is::DomainName($value)

Whether the value is already a valid domain name, unchanged by To::DomainName.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid domain name.

DriveLetter

Is::DriveLetter($bit)

Whether the value is a drive letter followed by a colon, such as C:.

NameTypeDescription
$bitThe value to test.

Returns bool True when the value is a letter followed by a colon.

Email

Is::Email($value)

Whether the value is already a valid email address, unchanged by To::Email.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid email address.

Filename

Is::Filename($value)

Whether the value is already a valid filename, unchanged by To::Filename.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid filename.

FilePath

Is::FilePath($value)

Whether the value is already a valid file path, unchanged by To::FilePath.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid file path.

Float

Is::Float($value)

Whether the value is a float or a number.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a float or a number.

ID

Is::ID($value, $allow_zero = false)

Whether the value is a non-negative integer id, with zero allowed only when requested.

NameTypeDescription
$valueThe value to test.
$allow_zeroWhether zero counts as a valid id. Defaults to false.

Returns bool True when the value is a valid id.

Integer

Is::Integer($integer)

Whether the value consists only of digits.

NameTypeDescription
$integerThe value to test.

Returns int A truthy match count when the value is all digits.

MD5

Is::MD5($string)

Whether the value is a 32-character string of hexadecimal characters.

NameTypeDescription
$stringThe value to test.

Returns bool True when the value looks like an MD5 hash.

Null

Is::Null($value): bool

Whether the value is null.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is null.

Num

Is::Num($num, $min = null, $max = null, $allow_number_string = false)

Whether the value is a whole number, optionally within a range and optionally allowing a well-formed numeric string.

NameTypeDescription
$numThe value to test.
$minThe lowest value allowed, or null for no minimum.
$maxThe highest value allowed, or null for no maximum.
$allow_number_stringWhether a numeric string is accepted. Defaults to false.

Returns bool True when the value is a whole number within any range.

OneOf

Is::OneOf($value, $values)

Whether the string value is one of the allowed values, given as an array or a comma-separated list.

NameTypeDescription
$valueThe string to test.
$valuesThe allowed values as an array or a comma-separated string.

Returns bool True when the value matches one of the allowed values.

OneOfNum

Is::OneOfNum($value, $values)

Whether the integer value is one of the allowed numbers, given as an array or a comma-separated list.

NameTypeDescription
$valueThe integer to test.
$valuesThe allowed numbers as an array or a comma-separated string.

Returns bool True when the value matches one of the allowed numbers.

Str

Is::Str($string)

Whether the value is a string.

NameTypeDescription
$stringThe value to test.

Returns bool True when the value is a string.

StrOrNull

Is::StrOrNull($string)

Whether the value is null or a string.

NameTypeDescription
$stringThe value to test.

Returns bool True when the value is null or a string.

StrOrNum

Is::StrOrNum($value)

Whether the value is a string or a number.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a string or a number.

TrueFalse

Is::TrueFalse($value)

Whether the value is exactly true or false.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a boolean.

Type

Is::Type($value): string

The name of the value's type: null, integer, float, string, boolean, array or object. Throws for an unknown type.

NameTypeDescription
$valueThe value to inspect.

Returns string The name of the value's type.

Url

Is::Url($value)

Whether the value is a url with both a scheme and a host.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a url with a scheme and a host.

UrlName

Is::UrlName($value)

Whether the value is already a valid url name, unchanged by To::UrlName.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid url name.

UrlPath

Is::UrlPath($value)

Whether the value is already a valid url path, unchanged by To::UrlPath.

NameTypeDescription
$valueThe value to test.

Returns bool True when the value is a valid url path.