class TypeComparison (View source)

Type comparison utility

Methods

static number
compare(mixed $a, mixed $b)

No description

static number
compareDateTime(DateTimeInterface $a, DateTimeInterface|string|integer|float $b, number $fractionEpsilon = 1)

No description

static 
compareBoolean($a, $b)

No description

static 
compareNumber($a, $b)

No description

static 
compareString($a, $b)

No description

Details

static number compare(mixed $a, mixed $b)

Parameters

mixed $a Left operand
mixed $b Right operand

Return Value

number
  • 0 if $a and $b are equal. - < 0 If $a is lesser than $b - > 0 if $a is greater than $b This method uses the following rules - NULL is lower than everything except itself. - FALSE is lower than anything that evaluates to TRUE and equals anything that evaluates to FALSE (except NULL). - TRUE is greater than anything that evaluates to FALSE. - Two numbers are cmopared using the minus operator - Two strings are compared using the \strcmp() function - Numbers are compared to strings by casting the string to number if possible

Exceptions

ComparisonException

static number compareDateTime(DateTimeInterface $a, DateTimeInterface|string|integer|float $b, number $fractionEpsilon = 1)

Parameters

DateTimeInterface $a First operand
DateTimeInterface|string|integer|float $b Second operand. DateTime, string representation of a DateTime, UNIX timestamp or julian day
number $fractionEpsilon Threshold to use in \DateTimeInterface fraction field comparison. If $fractionEpsilon > 1 A UNIX timestamp comparison is made instead.

Return Value

number

Exceptions

NotComparableException

static protected compareBoolean($a, $b)

Parameters

$a
$b

static protected compareNumber($a, $b)

Parameters

$a
$b

static protected compareString($a, $b)

Parameters

$a
$b