State::offsetExists()

Checks if a state with a certain key exists.

Table of Contents
  1. Description
  2. Example

Description

State::offsetExists(mixed $key): bool;

This method is a requirement to be able to implement the ArrayAccess interface and aims to make the object data accessible using array access syntax. You won’t use this method directly, it will be executed automatically when you try to check the existence of a state with array access syntax. This method checks if a state with a certain key exists and will only work when checked using empty() or isset() language construct.

Example

$state = new State([
    'bar' => 1,
    'baz-qux' => 2,
    'foo' => ""
]);

test(empty($state['asdf'])); // Returns `true`
test(empty($state['bar'])); // Returns `false`
test(empty($state['foo'])); // Returns `true`
test(isset($state['bar'])); // Returns `true`
test(isset($state['baz-qux'])); // Returns `true`
test(isset($state['bazQux'])); // Returns `false`
test(isset($state->bazQux)); // Returns `true` (see `State::__isset()`)
test(isset($state->{'baz-qux'})); // Returns `true` (see `State::__isset()`)

State::offsetExists()

Checks if a state with a certain key exists.