PHP Basics

StrictList extends SplDoublyLinkedList
in package
Uses StrictSplDoublyLinkedListTrait

A type-sensitive, taversable list.

Extends \SplDoublyLinkedList with an option to restrict the allowed data types for list items by providing the constructor with an array of atomic types or fully qualified class names.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

template

AllowedType of mixed

Table of Contents

Methods

__construct()  : void
Create a type-sensitive, traversable list of items.
add()  : void
Add/insert a new item at the specified offset.
append()  : void
Append items at the end of the list.
clear()  : void
Clear the list of any items.
get()  : AllowedType
Get the item at the specified index.
isList()  : true
Check if this can be considered a list.
offsetSet()  : void
Set the item at the specified offset.
prepend()  : void
Prepend items at the start of the list.
push()  : void
Push an item at the end of the list.
remove()  : void
Remove an item from the list.
set()  : void
Set an item at the specified index.
toArray()  : array<int, AllowedType>
Return array representation of list.
toStrictCollection()  : StrictCollection<string|int, AllowedType>
Turn list into a type-sensitive collection.
unshift()  : void
Prepend the list with an item.

Methods

__construct()

Create a type-sensitive, traversable list of items.

public __construct([array<string|int, string> $allowedTypes = [] ]) : void
Parameters
$allowedTypes : array<string|int, string> = []

Allowed data types of items (optional)

If empty, all types are allowed. Possible values are:

  • "array"
  • "bool"
  • "callable"
  • "countable"
  • "float" or "double"
  • "int" or "integer" or "long"
  • "iterable"
  • "null"
  • "numeric"
  • "object" or FQCN
  • "resource"
  • "scalar"
  • "string"
Tags
throws
InvalidArgumentException

if any value of $allowedTypes is not a string

add()

Add/insert a new item at the specified offset.

public add(int $offset, AllowedType $value) : void
APIYes
Parameters
$offset : int

The offset where the new item is to be inserted

$value : AllowedType

The new item for the offset

Tags
throws
InvalidDataTypeException

if $value is not of allowed type

throws
OutOfRangeException

when $offset is out of bounds

get()

Get the item at the specified index.

public get(int $offset) : AllowedType
APIYes
Parameters
$offset : int

The item's index

Tags
throws
OutOfRangeException

when $offset is out of bounds

Return values
AllowedType

The item

isList()

Check if this can be considered a list.

public isList() : true
APIYes
Return values
true

Always TRUE (this exists only for compatibility reasons)

offsetSet()

Set the item at the specified offset.

public offsetSet(int|null $offset, AllowedType $value) : void
APIYes
Parameters
$offset : int|null

The offset being set or NULL to append

$value : AllowedType

The new item for the offset

Tags
throws
InvalidDataTypeException

if $value is not of allowed type

throws
OutOfRangeException

when $offset is out of bounds

remove()

Remove an item from the list.

public remove(int $offset) : void
APIYes
Parameters
$offset : int

The item's index

Tags
throws
OutOfRangeException

when $offset is out of bounds

toArray()

Return array representation of list.

public toArray() : array<int, AllowedType>
APIYes
Return values
array<int, AllowedType>

Array of list items


        
On this page

Search results