MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

tArray

MMO\core\classes · 1 symbole · générée le 27 Oct 2026

trait

tArray

tArray.php:16

Trait implementing iArray: gives a class array-like storage (ArrayAccess, Countable, IteratorAggregate, JsonSerializable) backed by a single protected $content array.

trait MMO\core\classes\tArray
Espace de noms
MMO\core\classes
class Bag implements iArray, \JsonSerializable {use tArray;} $bag = new Bag(); $bag['x'] = 1; $bag[] = 2;// no key: appended, like a plain array var_dump($bag['x'], count($bag), $bag->toArray());// 1, 2, ['x' => 1, 0 => 2]

Index

content
clear()Empty the underlying content, keeping the object itself.
count()\Countable::count
getIterator()\IteratorAggregate::getIterator
isEmpty()
jsonSerialize()\JsonSerializable::jsonSerialize -- the raw content is returned as-is (not recursively converted), so json_encode() relies on any nested iArray values being JsonSerializable themselves.
keys()
loadArray($data)Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g.
offsetExists($key)\ArrayAccess::offsetExists
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
offsetUnset($key)\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain …
toArray()Convert the content to a plain array, recursively converting any nested iArray value (e.g.

Propriétés1

content

protected $content = []

Méthodes12

clear()

tArray.php:25

Empty the underlying content, keeping the object itself.

function clear()
retourne
$bag->clear(); // count($bag) === 0 afterwards

isEmpty()

tArray.php:33
function isEmpty()
retournetrue if the underlying content has no elements
$bag->isEmpty(); // true right after clear(), false as soon as an item is set

jsonSerialize()

tArray.php:43

\JsonSerializable::jsonSerialize -- the raw content is returned as-is (not recursively converted), so json_encode() relies on any nested iArray values being JsonSerializable themselves.

function jsonSerialize(): mixed
retournemixed
json_encode($bag); // e.g. '{"x":1,"0":2}'

keys()

tArray.php:82
function keys(): array
retournearraythe list of keys currently set
$bag->keys(); // e.g. ['x', 0]

loadArray($data)

tArray.php:71

Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g. for validation or type coercion, is honored for every entry).

function loadArray(array $data): static
$dataarray
retournestatic$this, for chaining
$bag->loadArray(['x' => 1, 'y' => 2]); // equivalent to $bag['x'] = 1; $bag['y'] = 2;

offsetExists($key)

tArray.php:130

\ArrayAccess::offsetExists

function offsetExists(mixed $key): bool
$keymixed
retournebool

offsetSet($key, $value)

tArray.php:122

\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.

function offsetSet(mixed $key, mixed $value): void
$keymixed
$valuemixed
retournevoid

offsetUnset($key)

tArray.php:107

\ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain PHP list; on an associative array, the key is simply removed.

function offsetUnset(mixed $key): void
$keymixed
retournevoid
unset($bag[0]); // on a list: every following index shifts down by one, like array_splice()

toArray()

tArray.php:56

Convert the content to a plain array, recursively converting any nested iArray value (e.g. another object using this same trait) into its own plain-array form as well.

function toArray(): array
retournearray
$inner = new Bag(); $inner['a'] = 1; $outer = new Bag(); $outer['inner'] = $inner; $outer->toArray(); // ['inner' => ['a' => 1]] -- $inner is recursively expanded, not left as an object