0 follower

Trait yii\base\ArrayAccessTrait

Implemented byyii\test\ActiveFixture, yii\test\ArrayFixture, yii\test\BaseActiveFixture
Available since version2.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

Hide inherited properties

Property Type Description Defined By
$data array yii\base\ArrayAccessTrait

Public Methods

Hide inherited 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

Hide inherited properties

$data public property
public array $data null

Method Details

Hide inherited methods

count() public method

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);
}

            
getIterator() public method

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);
}

            
offsetExists() public method

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]);
}

            
offsetGet() public method

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;
}

            
offsetSet() public method

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;
}

            
offsetUnset() public method

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]);
}