Trait yii\base\ArrayAccessTrait
Implemented by | yii\test\ActiveFixture, yii\test\ArrayFixture, yii\test\BaseActiveFixture |
---|---|
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/base/ArrayAccessTrait.php |
ArrayAccessTrait provides the implementation for IteratorAggregate, ArrayAccess and Countable.
Note that ArrayAccessTrait requires the class using it contain a property named data
which should be an array.
The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$data | array | yii\base\ArrayAccessTrait |
Public Methods
Method | Description | Defined By |
---|---|---|
count() | Returns the number of data items. | yii\base\ArrayAccessTrait |
getIterator() | Returns an iterator for traversing the data. | yii\base\ArrayAccessTrait |
offsetExists() | This method is required by the interface ArrayAccess. | yii\base\ArrayAccessTrait |
offsetGet() | This method is required by the interface ArrayAccess. | yii\base\ArrayAccessTrait |
offsetSet() | This method is required by the interface ArrayAccess. | yii\base\ArrayAccessTrait |
offsetUnset() | This method is required by the interface ArrayAccess. | yii\base\ArrayAccessTrait |
Property Details
Method Details
Returns the number of data items.
This method is required by Countable interface.
public integer count ( ) | ||
return | integer |
Number of data elements. |
---|
#[\ReturnTypeWillChange]
public function count()
{
return count($this->data);
}
Returns an iterator for traversing the data.
This method is required by the SPL interface IteratorAggregate.
It will be implicitly called when you use foreach
to traverse the collection.
public ArrayIterator getIterator ( ) | ||
return | ArrayIterator |
An iterator for traversing the cookies in the collection. |
---|
#[\ReturnTypeWillChange]
public function getIterator()
{
return new \ArrayIterator($this->data);
}
This method is required by the interface ArrayAccess.
public boolean offsetExists ( $offset ) | ||
$offset | mixed |
The offset to check on |
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->data[$offset]);
}
This method is required by the interface ArrayAccess.
public mixed offsetGet ( $offset ) | ||
$offset | integer |
The offset to retrieve element. |
return | mixed |
The element at the offset, null if no element is found at the offset |
---|
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}
This method is required by the interface ArrayAccess.
public void offsetSet ( $offset, $item ) | ||
$offset | integer |
The offset to set element |
$item | mixed |
The element value |
#[\ReturnTypeWillChange]
public function offsetSet($offset, $item)
{
$this->data[$offset] = $item;
}
This method is required by the interface ArrayAccess.
public void offsetUnset ( $offset ) | ||
$offset | mixed |
The offset to unset element |
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
Signup or Login in order to comment.