abstract class AbstractCollection extends AbstractArray implements CollectionInterface (View source)

This class provides an implementation of the CollectionInterface, to minimize the effort required to implement this interface

Traits

Provides functionality to check values for specific types
Provides functionality to express a value as string

Properties

protected array $data from AbstractArray

Methods

__construct(array $data = [])

Constructs a new array object

getIterator()

Returns a new iterator from this array

bool
offsetExists(mixed $offset)

Checks whether the specified offset exists in the array

mixed
offsetGet(mixed $offset)

Returns the value stored at the specified offset in the array

offsetSet(mixed $offset, mixed $value)

Sets the specified offset in the map with the given value

offsetUnset(mixed $offset)

Removes the specified offset and its value from the map

string
serialize()

Converts this map object to a string when the object is serialized with serialize()

unserialize(string $serialized)

Re-constructs the object from its serialized form

int
count()

Returns the number of elements contained in this array

void
clear()

Remove all the elements from this array object

toArray()

Returns a native PHP array containing all of the elements in this array object

bool
isEmpty()

Returns true if this array object contains no elements

bool
checkType(string $type, mixed $value)

Returns true if value is of the specified type

from TypeTrait
string
toolValueToString(mixed $value)

Return a string with the information of the value null value: NULL boolean: TRUE, FALSE array: Array scalar: converted-value resource: (type resource #number) object with __toString(): result of __toString() object DateTime: ISO 8601 date object: (className Object) anonymous function: same as object

bool
add(mixed $element)

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

bool
contains(mixed $element, bool $strict = true)

Returns true if this collection contains the specified element

bool
remove(mixed $element)

Removes a single instance of the specified element from this collection, if it is present

Details

__construct(array $data = [])

Constructs a new array object

Parameters

array $data

ArrayIterator getIterator()

Returns a new iterator from this array

Return Value

ArrayIterator

bool offsetExists(mixed $offset)

Checks whether the specified offset exists in the array

Parameters

mixed $offset

Return Value

bool

mixed offsetGet(mixed $offset)

Returns the value stored at the specified offset in the array

Parameters

mixed $offset

Return Value

mixed

offsetSet(mixed $offset, mixed $value)

Sets the specified offset in the map with the given value

Parameters

mixed $offset
mixed $value

Exceptions

InvalidArgumentException

offsetUnset(mixed $offset)

Removes the specified offset and its value from the map

Parameters

mixed $offset

string serialize()

Converts this map object to a string when the object is serialized with serialize()

Return Value

string

unserialize(string $serialized)

Re-constructs the object from its serialized form

Parameters

string $serialized

int count()

Returns the number of elements contained in this array

Return Value

int

void clear()

Remove all the elements from this array object

Return Value

void

toArray()

Returns a native PHP array containing all of the elements in this array object

bool isEmpty()

Returns true if this array object contains no elements

Return Value

bool

protected bool checkType(string $type, mixed $value)

Returns true if value is of the specified type

Parameters

string $type
mixed $value

Return Value

bool

protected string toolValueToString(mixed $value)

Return a string with the information of the value null value: NULL boolean: TRUE, FALSE array: Array scalar: converted-value resource: (type resource #number) object with __toString(): result of __toString() object DateTime: ISO 8601 date object: (className Object) anonymous function: same as object

Parameters

mixed $value

Return Value

string

bool add(mixed $element)

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters

mixed $element

Return Value

bool true if this collection changed as a result of the call

bool contains(mixed $element, bool $strict = true)

Returns true if this collection contains the specified element

Parameters

mixed $element
bool $strict Whether to perform a strict type check on the value.

Return Value

bool

bool remove(mixed $element)

Removes a single instance of the specified element from this collection, if it is present

Parameters

mixed $element

Return Value

bool true if an element was removed as a result of this call