for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\ActiveRecord\Trait;
use function property_exists;
/**
* Trait to implement {@see ArrayAccess} interface for ActiveRecord.
*/
trait ArrayAccessTrait
{
* Returns whether there is an element at the specified offset.
*
* This method is required by the SPL interface {@see ArrayAccess}.
* It is implicitly called when you use something like `isset($model[$offset])`.
* @return bool whether or not an offset exists.
public function offsetExists(mixed $offset): bool
return isset($this->$offset);
}
public function offsetGet(mixed $offset): mixed
return $this->$offset;
* Sets the element at the specified offset.
* It is implicitly called when you use something like `$model[$offset] = $item;`.
public function offsetSet(mixed $offset, mixed $value): void
$this->$offset = $value;
* Sets the element value at the specified offset to null.
* It is implicitly called when you use something like `unset($model[$offset])`.
public function offsetUnset(mixed $offset): void
if (is_string($offset) && property_exists($this, $offset)) {
$this->$offset = null;
} else {
unset($this->$offset);