Methods32
function addListener(callable $callable, ?object $target = null): voidfunction canCommute(): boolfunction canInverseEquality(): boolEmpty the underlying content, keeping the object itself.
function clear()$bag->clear(); // count($bag) === 0 afterwards
function commute(): MMO\math\interfaces\iNumberfunction compareTo(mixed $value): int|boolTest if operation contains the number or an instance of it
function contains(MMO\math\interfaces\iNumber|string $num): bool\Countable::count
function count(): intfunction debugName(): stringfunction execute(): mixed\IteratorAggregate::getIterator
function getIterator(): Traversablefunction getOperator(): callablefunction hasUnits(): boolfunction intervals(): arrayfunction inverseEquality(MMO\math\interfaces\iNumber|int|float|null $value = null): MMO\math\interfaces\iNumber|int|floatfunction isEmpty()| returns | | true if the underlying content has no elements |
$bag->isEmpty(); // true right after clear(), false as soon as an item is set
\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(): mixedjson_encode($bag); // e.g. '{"x":1,"0":2}'
function keys(): array| returns | array | the list of keys currently set |
$bag->keys(); // e.g. ['x', 0]
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$bag->loadArray(['x' => 1, 'y' => 2]); // equivalent to $bag['x'] = 1; $bag['y'] = 2;
function loopNumber(): Generatorfunction numberValue(): int|float|null\ArrayAccess::offsetExists
function offsetExists(mixed $key): bool\ArrayAccess::offsetGet
function offsetGet(mixed $key): mixed\ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array.
function offsetSet(mixed $key, mixed $value): void\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): voidunset($bag[0]); // on a list: every following index shifts down by one, like array_splice()
function removeListener(callable|object $callable): voidfunction simplify(): MMO\math\interfaces\iNumber|int|floatConvert 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$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
Get the units of this operation.
function units(): ?MMO\math\helpers\UnitsIf the operator is Arithmetic, the first 2 arguments are used to compute the unitsfunction __construct(callable $operator, mixed ...$args)function __toString(): string