Documentation

TypedArray implements ArrayAccess, Countable, IteratorAggregate

Tags
implements

ArrayAccess<mixed, mixed>

implements

IteratorAggregate<int|string, mixed>

see
https://www.php.net/manual/en/class.arrayaccess.php
see
https://www.php.net/manual/en/class.countable.php
see
https://www.php.net/manual/en/class.iteratoraggregate.php
phpstan-template

TKey

phpstan-template

TValue

phpstan-implements

ArrayAccess<TKey, TValue>

phpstan-implements

IteratorAggregate<int|string, TValue>

psalm-template

TKey

psalm-template

TValue

template-implements

ArrayAccess<TKey, TValue>

template-implements

IteratorAggregate<int|string, TValue>

psalm-type

IntArrayKey int|null

Interfaces, Classes and Traits

ArrayAccess
Countable
IteratorAggregate

Table of Contents

KEY_CLASS_KINDS  = ['class' => 'class', 'interface' => 'interface', 'trait' => 'trait']
KEY_TYPES  = ['bool' => 'bool', 'float' => 'float', 'int' => 'int', 'mixed' => 'mixed', 'object' => 'object', 'resource' => 'resource', 'string' => 'string']
VALUE_CLASS_KINDS  = ['class' => 'class', 'interface' => 'interface', 'trait' => 'trait']
VALUE_TYPES  = ['array' => 'array', 'bool' => 'bool', 'float' => 'float', 'int' => 'int', 'mixed' => 'mixed', 'object' => 'object', 'resource' => 'resource', 'string' => 'string']
$keyClassKind  : string|null
$keys  : array<int|string, mixed>
The hash map of key's hash codes and keys.
$keyType  : string
$valueClassKind  : string|null
$values  : array<int|string, mixed>
The hash map of key's hash codes and values.
$valueType  : string
count()  : int
getIterator()  : ArrayIterator<int|string, mixed>
isEmpty()  : bool
Determines if the typed array is empty or not.
new()  : TypedArray<mixed, mixed>
Creates a new instance of the typed array.
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
toArray()  : array<int|string, mixed>
Gets the typed array of values as a plain array.
withArrayValue()  : TypedArray<mixed, array<int|string, mixed>>
Returns a new instance of the typed array with the array type value.
withBoolKey()  : TypedArray<bool, mixed>
Returns a new instance of the typed array with the bool type key.
withBoolValue()  : TypedArray<mixed, bool>
Returns a new instance of the typed array with the bool type value.
withClassKey()  : TypedArray<object, mixed>
Returns a new instance of the typed array with the specified class type key.
withClassValue()  : TypedArray<mixed, object>
Returns a new instance of the typed array with the specified class type value.
withFloatKey()  : TypedArray<float, mixed>
Returns a new instance of the typed array with the float type key.
withFloatValue()  : TypedArray<mixed, float>
Returns a new instance of the typed array with the float type value.
withInterfaceKey()  : TypedArray<object, mixed>
Returns a new instance of the typed array with the class type key that implements the specified interface.
withInterfaceValue()  : TypedArray<mixed, object>
Returns a new instance of the typed array with the class type value that implements the specified interface.
withIntKey()  : TypedArray<int|null, mixed>
Returns a new instance of the typed array with the int type key.
withIntValue()  : TypedArray<mixed, int>
Returns a new instance of the typed array with the int type value.
withMixedKey()  : TypedArray<mixed, mixed>
Returns a new instance of the typed array with the mixed type key.
withMixedValue()  : TypedArray<mixed, mixed>
Returns a new instance of the typed array with the mixed type value.
withObjectKey()  : TypedArray<object, mixed>
Returns a new instance of the typed array with the object type key.
withObjectValue()  : TypedArray<mixed, object>
Returns a new instance of the typed array with the object type value.
withResourceKey()  : TypedArray<resource, mixed>
Returns a new instance of the typed array with the resource type key.
withResourceValue()  : TypedArray<mixed, resource>
Returns a new instance of the typed array with the resource type value.
withStringKey()  : TypedArray<string, mixed>
Returns a new instance of the typed array with the string type key.
withStringValue()  : TypedArray<mixed, string>
Returns a new instance of the typed array with the string type value.
withTraitKey()  : TypedArray<object, mixed>
Returns a new instance of the typed array with the class type key that uses the specified trait.
withTraitValue()  : TypedArray<mixed, object>
Returns a new instance of the typed array with the class type value that uses the specified trait.
__construct()  : mixed
getKeyHashCode()  : int|string|null
keyExists()  : bool

Constants

KEY_CLASS_KINDS

private mixed KEY_CLASS_KINDS = ['class' => 'class', 'interface' => 'interface', 'trait' => 'trait']

KEY_TYPES

private mixed KEY_TYPES = ['bool' => 'bool', 'float' => 'float', 'int' => 'int', 'mixed' => 'mixed', 'object' => 'object', 'resource' => 'resource', 'string' => 'string']

VALUE_CLASS_KINDS

private mixed VALUE_CLASS_KINDS = ['class' => 'class', 'interface' => 'interface', 'trait' => 'trait']

VALUE_TYPES

private mixed VALUE_TYPES = ['array' => 'array', 'bool' => 'bool', 'float' => 'float', 'int' => 'int', 'mixed' => 'mixed', 'object' => 'object', 'resource' => 'resource', 'string' => 'string']

Properties

$keys

The hash map of key's hash codes and keys.

private array<int|string, mixed> $keys = []

This is only used when the key type is the object, class, interface, or trait type.

Tags
phpstan-var

array<int|string, TKey>

psalm-var

array<int|string, TKey>

$keyType

private string $keyType
Tags
phpstan-var

class-string|string

psalm-var

class-string|string

$valueClassKind

private string|null $valueClassKind

$values

The hash map of key's hash codes and values.

private array<int|string, mixed> $values = []
Tags
phpstan-var

array<int|string, TValue>

psalm-var

array<int|string, TValue>

$valueType

private string $valueType
Tags
phpstan-var

class-string|string

psalm-var

class-string|string

Methods

getIterator()

public getIterator() : ArrayIterator<int|string, mixed>
Tags
see
https://www.php.net/manual/en/iteratoraggregate.getiterator.php
phpstan-return

ArrayIterator<int|string, TValue>

psalm-return

ArrayIterator<( TKey is IntArrayKey|object ? int : (TKey is bool|float|string|resource ? string : int|string) ), TValue>

Return values
ArrayIterator<int|string, mixed>

isEmpty()

Determines if the typed array is empty or not.

public isEmpty() : bool
Return values
bool

toArray()

Gets the typed array of values as a plain array.

public toArray() : array<int|string, mixed>
Tags
phpstan-return

array<int|string, TValue>

psalm-return

array<( TKey is IntArrayKey|object ? int : (TKey is bool|float|string|resource ? string : int|string) ), TValue>

Return values
array<int|string, mixed>

withArrayValue()

Returns a new instance of the typed array with the array type value.

public withArrayValue() : TypedArray<mixed, array<int|string, mixed>>
Tags
phpstan-return

TypedArray<TKey, array<int|string, mixed>>

psalm-return

TypedArray<TKey, array<int|string, mixed>>

Return values
TypedArray<mixed, array<int|string, mixed>>

withBoolKey()

Returns a new instance of the typed array with the bool type key.

public withBoolKey() : TypedArray<bool, mixed>
Tags
phpstan-return

TypedArray<bool, TValue>

psalm-return

TypedArray<bool, TValue>

Return values
TypedArray<bool, mixed>

withBoolValue()

Returns a new instance of the typed array with the bool type value.

public withBoolValue() : TypedArray<mixed, bool>
Tags
phpstan-return

TypedArray<TKey, bool>

psalm-return

TypedArray<TKey, bool>

Return values
TypedArray<mixed, bool>

withClassKey()

Returns a new instance of the typed array with the specified class type key.

public withClassKey(string $class) : TypedArray<object, mixed>

If you are using an object as the key, it is recommended that you implement the equals() and hashCode() methods on the object to determine whether keys are equal or not. Otherwise, the === operator and spl_object_id() function are used to determine it.

Parameters
$class : string
Tags
see
Class7
phpstan-template

TClass

phpstan-param

class-string $class

phpstan-return

TypedArray<TClass, TValue>

psalm-template

TClass

psalm-param

class-string $class

psalm-return

TypedArray<TClass, TValue>

Return values
TypedArray<object, mixed>

withClassValue()

Returns a new instance of the typed array with the specified class type value.

public withClassValue(string $class) : TypedArray<mixed, object>
Parameters
$class : string
Tags
phpstan-template

TClass

phpstan-param

class-string $class

phpstan-return

TypedArray<TKey, TClass>

psalm-template

TClass

psalm-param

class-string $class

psalm-return

TypedArray<TKey, TClass>

Return values
TypedArray<mixed, object>

withFloatKey()

Returns a new instance of the typed array with the float type key.

public withFloatKey() : TypedArray<float, mixed>
Tags
phpstan-return

TypedArray<float, TValue>

psalm-return

TypedArray<float, TValue>

Return values
TypedArray<float, mixed>

withFloatValue()

Returns a new instance of the typed array with the float type value.

public withFloatValue() : TypedArray<mixed, float>
Tags
phpstan-return

TypedArray<TKey, float>

psalm-return

TypedArray<TKey, float>

Return values
TypedArray<mixed, float>

withInterfaceKey()

Returns a new instance of the typed array with the class type key that implements the specified interface.

public withInterfaceKey(string $interface) : TypedArray<object, mixed>

If you are using an object as the key, it is recommended that you implement the equals() and hashCode() methods on the object to determine whether keys are equal or not. Otherwise, the === operator and spl_object_id() function are used to determine it.

Parameters
$interface : string
Tags
see
Class7
phpstan-template

TInterface

phpstan-param

class-string $interface

phpstan-return

TypedArray<TInterface, TValue>

psalm-template

TInterface

psalm-param

class-string $interface

psalm-return

TypedArray<TInterface, TValue>

Return values
TypedArray<object, mixed>

withInterfaceValue()

Returns a new instance of the typed array with the class type value that implements the specified interface.

public withInterfaceValue(string $interface) : TypedArray<mixed, object>
Parameters
$interface : string
Tags
phpstan-template

TInterface

phpstan-param

class-string $interface

phpstan-return

TypedArray<TKey, TInterface>

psalm-template

TInterface

psalm-param

class-string $interface

psalm-return

TypedArray<TKey, TInterface>

Return values
TypedArray<mixed, object>

withIntKey()

Returns a new instance of the typed array with the int type key.

public withIntKey() : TypedArray<int|null, mixed>
Tags
phpstan-return

TypedArray<int|null, TValue>

psalm-return

TypedArray<IntArrayKey, TValue>

Return values
TypedArray<int|null, mixed>

withIntValue()

Returns a new instance of the typed array with the int type value.

public withIntValue() : TypedArray<mixed, int>
Tags
phpstan-return

TypedArray<TKey, int>

psalm-return

TypedArray<TKey, int>

Return values
TypedArray<mixed, int>

withMixedKey()

Returns a new instance of the typed array with the mixed type key.

public withMixedKey() : TypedArray<mixed, mixed>
Tags
phpstan-return

TypedArray<mixed, TValue>

psalm-return

TypedArray<mixed, TValue>

Return values
TypedArray<mixed, mixed>

withMixedValue()

Returns a new instance of the typed array with the mixed type value.

public withMixedValue() : TypedArray<mixed, mixed>
Tags
phpstan-return

TypedArray<TKey, mixed>

psalm-return

TypedArray<TKey, mixed>

Return values
TypedArray<mixed, mixed>

withObjectKey()

Returns a new instance of the typed array with the object type key.

public withObjectKey() : TypedArray<object, mixed>

If you are using an object as the key, it is recommended that you implement the equals() and hashCode() methods on the object to determine whether keys are equal or not. Otherwise, the === operator and spl_object_id() function are used to determine it.

Tags
see
Class7
phpstan-return

TypedArray<object, TValue>

psalm-return

TypedArray<object, TValue>

Return values
TypedArray<object, mixed>

withObjectValue()

Returns a new instance of the typed array with the object type value.

public withObjectValue() : TypedArray<mixed, object>
Tags
phpstan-return

TypedArray<TKey, object>

psalm-return

TypedArray<TKey, object>

Return values
TypedArray<mixed, object>

withResourceKey()

Returns a new instance of the typed array with the resource type key.

public withResourceKey() : TypedArray<resource, mixed>
Tags
phpstan-return

TypedArray<resource, TValue>

psalm-return

TypedArray<resource, TValue>

Return values
TypedArray<resource, mixed>

withResourceValue()

Returns a new instance of the typed array with the resource type value.

public withResourceValue() : TypedArray<mixed, resource>
Tags
phpstan-return

TypedArray<TKey, resource>

psalm-return

TypedArray<TKey, resource>

Return values
TypedArray<mixed, resource>

withStringKey()

Returns a new instance of the typed array with the string type key.

public withStringKey() : TypedArray<string, mixed>
Tags
phpstan-return

TypedArray<string, TValue>

psalm-return

TypedArray<string, TValue>

Return values
TypedArray<string, mixed>

withStringValue()

Returns a new instance of the typed array with the string type value.

public withStringValue() : TypedArray<mixed, string>
Tags
phpstan-return

TypedArray<TKey, string>

psalm-return

TypedArray<TKey, string>

Return values
TypedArray<mixed, string>

withTraitKey()

Returns a new instance of the typed array with the class type key that uses the specified trait.

public withTraitKey(string $trait) : TypedArray<object, mixed>

If you are using an object as the key, it is recommended that you implement the equals() and hashCode() methods on the object to determine whether keys are equal or not. Otherwise, the === operator and spl_object_id() function are used to determine it.

Parameters
$trait : string
Tags
see
Class7
phpstan-param

class-string $trait

phpstan-return

TypedArray<object, TValue>

psalm-param

trait-string $trait

psalm-return

TypedArray<object, TValue>

Return values
TypedArray<object, mixed>

withTraitValue()

Returns a new instance of the typed array with the class type value that uses the specified trait.

public withTraitValue(string $trait) : TypedArray<mixed, object>
Parameters
$trait : string
Tags
phpstan-param

class-string $trait

phpstan-return

TypedArray<TKey, object>

psalm-param

trait-string $trait

psalm-return

TypedArray<TKey, object>

Return values
TypedArray<mixed, object>

__construct()

private __construct(string $keyType, string|null $keyClassKind, string $valueType, string|null $valueClassKind) : mixed
Parameters
$keyType : string
$keyClassKind : string|null
$valueType : string
$valueClassKind : string|null
Return values
mixed

getKeyHashCode()

private getKeyHashCode(mixed $key) : int|string|null
Parameters
$key : mixed
Tags
phpstan-param

TKey $key

phpstan-return

int|string|null

psalm-param

TKey $key

psalm-return

IntArrayKey|string

Return values
int|string|null

keyExists()

private keyExists(mixed $key, int|string|null $keyHashCode) : bool
Parameters
$key : mixed
$keyHashCode : int|string|null
Tags
phpstan-param

TKey $key

phpstan-param

int|string|null $keyHashCode

psalm-param

TKey $key

psalm-param

IntArrayKey|string $keyHashCode

Return values
bool

Search results