class QueryString implements Serializable, ArrayAccess, IteratorAggregate (View source)

The http\QueryString class provides versatile facilities to retrieve, use and manipulate query strings and form data.

Constants

TYPE_BOOL

Cast requested value to bool.

TYPE_INT

Cast requested value to int.

TYPE_FLOAT

Cast requested value to float.

TYPE_STRING

Cast requested value to string.

TYPE_ARRAY

Cast requested value to an array.

TYPE_OBJECT

Cast requested value to an object.

Methods

__construct(mixed $params = null)

Create an independent querystring instance.

string
__toString()

Get the string representation of the querystring (x-www-form-urlencoded).

QueryString|string|mixed
get(string $name = null, mixed $type = null, mixed $defval = null, bool $delete = false)

Retrieve an querystring value.

array|mixed
getArray(string $name, mixed $defval = null, bool $delete = false)

Retrieve an array value with at offset $name.

bool|mixed
getBool(string $name, mixed $defval = null, bool $delete = false)

Retrieve a boolean value at offset $name.

float|mixed
getFloat(string $name, mixed $defval = null, bool $delete = false)

Retrieve a float value at offset $name.

getGlobalInstance()

Retrieve the global querystring instance referencing $_GET.

int|mixed
getInt(string $name, mixed $defval = null, bool $delete = false)

Retrieve a int value at offset $name.

getIterator()

Implements IteratorAggregate.

object|mixed
getObject(string $name, mixed $defval = null, bool $delete = false)

Retrieve a object value with at offset $name.

string|mixed
getString(string $name, mixed $defval = null, bool $delete = false)

Retrieve a string value with at offset $name.

mod(mixed $params = null)

Set additional $params to a clone of this instance.

bool
offsetExists(string $name)

Implements ArrayAccess.

mixed
offsetGet(TKey $offset)

Implements ArrayAccess.

void
offsetSet(string $name, mixed $data)

Implements ArrayAccess.

void
offsetUnset(string $name)

Implements ArrayAccess.

string|null
serialize()

Implements Serializable.

set(mixed $params)

Set additional querystring entries.

array
toArray()

Simply returns http\QueryString::$queryArray.

string
toString()

Get the string representation of the querystring (x-www-form-urlencoded).

void
unserialize(string $serialized)

Implements Serializable.

xlate(string $from_enc, string $to_enc)

Translate character encodings of the querystring with ext/iconv.

Details

__construct(mixed $params = null)

Create an independent querystring instance.

Parameters

mixed $params

The query parameters to use or parse.

Exceptions

BadQueryStringException

string __toString()

Get the string representation of the querystring (x-www-form-urlencoded).

Return Value

string

the x-www-form-urlencoded querystring.

QueryString|string|mixed get(string $name = null, mixed $type = null, mixed $defval = null, bool $delete = false)

Retrieve an querystring value.

See http\QueryString::TYPE_* constants.

Parameters

string $name

The key to retrieve the value for.

mixed $type

The type to cast the value to. See http\QueryString::TYPE_* constants.

mixed $defval

The default value to return if the key $name does not exist.

bool $delete

Whether to delete the entry from the querystring after retrieval.

Return Value

QueryString|string|mixed

\http\QueryString if called without arguments. or string the whole querystring if $name is of zero length. or mixed $defval if the key $name does not exist. or mixed the querystring value cast to $type if $type was specified and the key $name exists. or string the querystring value if the key $name exists and $type is not specified or equals http\QueryString::TYPE_STRING.

array|mixed getArray(string $name, mixed $defval = null, bool $delete = false)

Retrieve an array value with at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

array|mixed

array the (casted) value. or mixed $defval if offset $name does not exist.

bool|mixed getBool(string $name, mixed $defval = null, bool $delete = false)

Retrieve a boolean value at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

bool|mixed

bool the (casted) value. or mixed $defval if offset $name does not exist.

float|mixed getFloat(string $name, mixed $defval = null, bool $delete = false)

Retrieve a float value at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

float|mixed

float the (casted) value. or mixed $defval if offset $name does not exist.

QueryString getGlobalInstance()

Retrieve the global querystring instance referencing $_GET.

Return Value

QueryString

the http\QueryString::$instance

Exceptions

UnexpectedValueException

int|mixed getInt(string $name, mixed $defval = null, bool $delete = false)

Retrieve a int value at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

int|mixed

int the (casted) value. or mixed $defval if offset $name does not exist.

Traversable getIterator()

Implements IteratorAggregate.

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

Exceptions

InvalidArgumentException
InvalidArgumentException

object|mixed getObject(string $name, mixed $defval = null, bool $delete = false)

Retrieve a object value with at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

object|mixed

object the (casted) value. or mixed $defval if offset $name does not exist.

string|mixed getString(string $name, mixed $defval = null, bool $delete = false)

Retrieve a string value with at offset $name.

Parameters

string $name

The key to look up.

mixed $defval

The default value to return if the offset $name does not exist.

bool $delete

Whether to remove the key and value from the querystring after retrieval.

Return Value

string|mixed

string the (casted) value. or mixed $defval if offset $name does not exist.

QueryString mod(mixed $params = null)

Set additional $params to a clone of this instance.

See http\QueryString::set().

NOTE: This method returns a clone (copy) of this instance.

Parameters

mixed $params

Additional params as object, array or string to parse.

Return Value

QueryString clone.

Exceptions

BadQueryStringException

bool offsetExists(string $name)

Implements ArrayAccess.

Parameters

string $name

The offset to look up.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(TKey $offset)

Implements ArrayAccess.

Parameters

TKey $offset

The offset to retrieve.

Return Value

mixed

Can return all value types.

void offsetSet(string $name, mixed $data)

Implements ArrayAccess.

Parameters

string $name

The key to set the value for.

mixed $data

The data to place at offset $name.

Return Value

void

void offsetUnset(string $name)

Implements ArrayAccess.

Parameters

string $name

The offset to look up.

Return Value

void

string|null serialize()

Implements Serializable.

See http\QueryString::toString().

Return Value

string|null

The string representation of the object or null

QueryString set(mixed $params)

Set additional querystring entries.

Parameters

mixed $params

Additional params as object, array or string to parse.

Return Value

QueryString self.

array toArray()

Simply returns http\QueryString::$queryArray.

Return Value

array

the $queryArray property.

string toString()

Get the string representation of the querystring (x-www-form-urlencoded).

Return Value

string

the x-www-form-urlencoded querystring.

void unserialize(string $serialized)

Implements Serializable.

Parameters

string $serialized

The x-www-form-urlencoded querystring.

Return Value

void

Exceptions

Exception

QueryString xlate(string $from_enc, string $to_enc)

Translate character encodings of the querystring with ext/iconv.

NOTE: This method is only available when ext/iconv support was enabled at build time.

Parameters

string $from_enc

The encoding to convert from.

string $to_enc

The encoding to convert to.

Return Value

QueryString self.

Exceptions

InvalidArgumentException
BadConversionException