Oihana PHP Enums

FilterOption uses ConstantsTrait

Defines constants representing valid option keys for PHP's filter functions (e.g. {@see filter_var()}, {@see filter_input()}).

This class provides a type-safe alternative to using raw string keys such as 'flags', 'options', 'min_range', and 'max_range' when specifying filter options. Using constants reduces typos and improves code completion.

The ConstantsTrait allows you to retrieve these constants dynamically, for example to validate option names or iterate over all possible values.

Tags
example
use oihana\enums\FilterOption;

$param = '42';
$options =
[
    FilterOption::MIN_RANGE => 10,
    FilterOption::MAX_RANGE => 100,
];

$result = filter_var
(
    $param ,
    FILTER_VALIDATE_INT ,
    [ FilterOption::OPTIONS => $options ]
);

var_dump($result); // int(42) if within range, or false otherwise

Table of Contents

Constants

DEFAULT  : string = 'default'
FLAGS  : string = 'flags'
MAX_RANGE  : string = 'max_range'
MIN_RANGE  : string = 'min_range'
OPTIONS  : string = 'options'

Constants

DEFAULT

public string DEFAULT = 'default'

Default filter option (applies when no specific configuration is set).

FLAGS

public string FLAGS = 'flags'

Flags filter option (used for bitmask or special mode flags).

MAX_RANGE

public string MAX_RANGE = 'max_range'

Maximum range filter option (upper bound for range-based filters).

MIN_RANGE

public string MIN_RANGE = 'min_range'

Minimum range filter option (lower bound for range-based filters).

OPTIONS

public string OPTIONS = 'options'

Options list filter option (represents a set of allowed values or a config array).

On this page

Search results