State::get()

Gets a state or states.

Table of Contents
  1. Description
  2. Example

Description

State::get(): object;
State::get(array $keys, bool $array = false): array|object;
State::get(array $values, bool $array = false): array|object;
State::get(string $key, bool $array = false): mixed;

This method returns a state or states that was previously set. If a state key does not exist, this method returns an empty array, empty object, or null. It is possible to use dot notation access if you want to get the states recursively. To keep the dot character as part of the key, prefix it with a \.

Example

State::set([
    'bar' => 1,
    'baz' => true,
    'foo' => ['bar' => 5],
    'foo.bar' => 1,
    'qux' => [1, 2, 3]
]);

test(State::get('asdf')); // Returns `null`
test(State::get('bar')); // Returns `1`
test(State::get('bar', true)); // Returns `1`
test(State::get('foo')); // Returns `(object) ['bar' => 5]`
test(State::get('foo', true)); // Returns `['bar' => 5]`
test(State::get('foo.bar')); // Returns `5`
test(State::get('foo.bar', true)); // Returns `5`
test(State::get('foo\.bar')); // Returns `1`
test(State::get('foo\.bar', true)); // Returns `1`
test(State::get('qux.1')); // Returns `2`
test(State::get('qux.3')); // Returns `null`
test(State::get()); // Returns `(object) ['bar' => 1, 'baz' => true, 'foo' => [ … ], 'qux' => [ … ]]`
test(State::get([], true)); // Returns `['bar' => 1, 'baz' => true, 'foo' => [ … ], 'qux' => [ … ]]`
test(State::get([
    'asdf' => '#',
    'bar' => '#',
    'baz' => '#'
])); // Returns `(object) ['asdf' => '#', bar' => 1, 'baz' => true]`
test(State::get([
    'asdf' => '#',
    'bar' => '#',
    'baz' => '#'
], true)); // Returns `['asdf' => '#', bar' => 1, 'baz' => true]`
test(State::get(['asdf', 'bar', 'baz'])); // Returns `[null, 1, true]`
test(State::get(['asdf', 'bar', 'baz'], true)); // Returns `[null, 1, true]`

State::get()

Gets a state or states.