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.
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.
| Name | Type | Description |
|---|---|---|
$value | | The value to test. |
$optionalCheckCallback | | A 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The value to test. |
Returns bool True when the value is an array of strings.
Callback
Is::Callback($callback)
Whether the value is callable.
| Name | Type | Description |
|---|---|---|
$callback | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$date | | The 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.
| Name | Type | Description |
|---|---|---|
$date | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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:.
| Name | Type | Description |
|---|---|---|
$bit | | The value to test. |
Returns bool True when the value is a letter followed by a colon.
Is::Email($value)
Whether the value is already a valid email address, unchanged by To::Email.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The value to test. |
$allow_zero | | Whether 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.
| Name | Type | Description |
|---|---|---|
$integer | | The 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.
| Name | Type | Description |
|---|---|---|
$string | | The value to test. |
Returns bool True when the value looks like an MD5 hash.
Null
Is::Null($value): bool
Whether the value is null.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$num | | The value to test. |
$min | | The lowest value allowed, or null for no minimum. |
$max | | The highest value allowed, or null for no maximum. |
$allow_number_string | | Whether 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.
| Name | Type | Description |
|---|---|---|
$value | | The string to test. |
$values | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The integer to test. |
$values | | The 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.
| Name | Type | Description |
|---|---|---|
$string | | The value to test. |
Returns bool True when the value is a string.
StrOrNull
Is::StrOrNull($string)
Whether the value is null or a string.
| Name | Type | Description |
|---|---|---|
$string | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The 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.
| Name | Type | Description |
|---|---|---|
$value | | The value to test. |
Returns bool True when the value is a valid url path.