phpEZ v0.1.2

BoolGet extends Get
in package

Boolean query parameter accessor for GET requests.

Specialized Get class that interprets parameter values as truthy/falsy. Parameter absence or explicit false-like values ('0', 'false', 'no') are false. All other values are true.

Usage:

$debug = new BoolGet('debug');
if ($debug->trueish()) { ... }  // true if ?debug=1 or ?debug=yes, false otherwise
Tags
subpackage

http

Table of Contents

Properties

$key  : string

Methods

__construct()  : mixed
Initialize a GET parameter accessor.
trueish()  : bool
Check if the GET parameter is present and truthy.
v()  : string|null
Retrieve a GET parameter value with optional default.

Properties

$key read-only

protected string $key

Methods

__construct()

Initialize a GET parameter accessor.

public __construct(string $key) : mixed
Parameters
$key : string

The parameter name/key to access from $_GET.

trueish()

Check if the GET parameter is present and truthy.

public trueish() : bool

False-like values: missing parameter, '0', 'false', 'no' (case-insensitive). All other values (including parameter present but without value): true.

Return values
bool

True if the parameter is truthy, false otherwise.

v()

Retrieve a GET parameter value with optional default.

public v([string|null $default = null ]) : string|null
Parameters
$default : string|null = null

Default value if the parameter is not present.

Return values
string|null

The parameter value or default value.

On this page

Search results