ArrayExpression
in package
implements
ExpressionInterface, ArrayAccess, Countable, IteratorAggregate
Class ArrayExpression represents an array SQL expression.
Expressions of this type can be used in conditions as well:
$query->andWhere(['@>', 'items', new ArrayExpression([1, 2, 3], 'integer')])
which, depending on DBMS, will result in a well-prepared condition. For example, in
PostgreSQL it will be compiled to WHERE "items" @> ARRAY[1, 2, 3]::integer[]
.
Tags
Table of Contents
Interfaces
- ExpressionInterface
- Interface ExpressionInterface should be used to mark classes, that should be built in a special way.
- ArrayAccess
- Countable
- IteratorAggregate
Properties
- $dimension : int
- $type : string|null
- $value : array<string|int, mixed>|QueryInterface
Methods
- __construct() : mixed
- ArrayExpression constructor.
- count() : int
- Count elements of an object
- getDimension() : int
- getIterator() : Traversable
- Retrieve an external iterator
- getType() : string|null
- getValue() : array<string|int, mixed>|mixed|QueryInterface
- offsetExists() : bool
- Whether a offset exists
- offsetGet() : mixed
- Offset to retrieve
- offsetSet() : void
- Offset to set
- offsetUnset() : void
- Offset to unset
Properties
$dimension
private
int
$dimension
the number of indices needed to select an element
$type
private
string|null
$type
the type of the array elements. Defaults to null
which means the type is
not explicitly specified.
Note that in case when type is not specified explicitly and DBMS can not guess it from the context, SQL error will be raised.
$value
private
array<string|int, mixed>|QueryInterface
$value
the array's content. In can be represented as an array of values or a [[Query]] that returns these values.
Methods
__construct()
ArrayExpression constructor.
public
__construct(array<string|int, mixed>|QueryInterface|mixed $value[, string|null $type = null ][, int $dimension = 1 ]) : mixed
Parameters
- $value : array<string|int, mixed>|QueryInterface|mixed
-
the array content. Either represented as an array of values or a Query that returns these values. A single value will be considered as an array containing one element.
- $type : string|null = null
-
the type of the array elements. Defaults to
null
which means the type is not explicitly specified. In case when type is not specified explicitly and DBMS can not guess it from the context, SQL error will be raised. - $dimension : int = 1
-
the number of indices needed to select an element
count()
Count elements of an object
public
count() : int
Tags
Attributes
Return values
int —The custom count as an integer.
The return value is cast to an integer.
getDimension()
public
getDimension() : int
Return values
int —the number of indices needed to select an element
getIterator()
Retrieve an external iterator
public
getIterator() : Traversable
Tags
Attributes
Return values
Traversable —An instance of an object implementing Iterator or Traversable
getType()
public
getType() : string|null
Return values
string|nullgetValue()
public
getValue() : array<string|int, mixed>|mixed|QueryInterface
Return values
array<string|int, mixed>|mixed|QueryInterfaceoffsetExists()
Whether a offset exists
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
An offset to check for.
Tags
Attributes
Return values
bool —true on success or false on failure.
The return value will be casted to boolean if non-boolean was returned.
offsetGet()
Offset to retrieve
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
-
The offset to retrieve.
Tags
Attributes
Return values
mixed —Can return all value types.
offsetSet()
Offset to set
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
-
The offset to assign the value to.
- $value : mixed
-
The value to set.
Tags
Attributes
offsetUnset()
Offset to unset
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
-
The offset to unset.