Skip to content

Phalcon collection

NOTE

All classes are prefixed with Phalcon

Collection

Source on GitHub

  • Namespace

    • Phalcon\Support
  • Uses

    • ArrayAccess
    • ArrayIterator
    • Countable
    • InvalidArgumentException
    • IteratorAggregate
    • JsonSerializable
    • Phalcon\Collection\CollectionInterface
    • Serializable
    • Traversable
  • Extends

  • Implements

    • ArrayAccess
    • CollectionInterface
    • Countable
    • IteratorAggregate
    • JsonSerializable
    • Serializable

Phalcon\Collection is a supercharged object oriented array. It implements: - ArrayAccess - Countable - IteratorAggregate - JsonSerializable - Serializable

It can be used in any part of the application that needs collection of data Such implementations are for instance accessing globals $_GET, $_POST etc.

Properties

/**
 * @var array
 */
protected $data;

/**
 * @var bool
 */
protected $insensitive = true;

/**
 * @var array
 */
protected $lowerKeys;

Methods

public function __construct( array $data = [], bool $insensitive = bool );
Collection constructor.

public function __get( string $element ): mixed;
Magic getter to get an element from the collection

public function __isset( string $element ): bool;
Magic isset to check whether an element exists or not

public function __set( string $element, mixed $value ): void;
Magic setter to assign values to an element

public function __unset( string $element ): void;
Magic unset to remove an element from the collection

public function clear(): void;
Clears the internal collection

public function count(): int;
Count elements of an object. See count

public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
Get the element from the collection

public function getIterator(): Traversable;
Returns the iterator of the class

public function getKeys( bool $insensitive = bool ): array;
Return the keys as an array

public function getValues(): array;
Return the values as an array

public function has( string $element ): bool;
Determines whether an element is present in the collection.

public function init( array $data = [] ): void;
Initialize internal array

public function jsonSerialize(): array;
Specify data which should be serialized to JSON See jsonSerialize

public function offsetExists( mixed $element ): bool;
Whether a offset exists See offsetExists

public function offsetGet( mixed $element );
Offset to retrieve See offsetGet

public function offsetSet( mixed $element, mixed $value ): void;
Offset to set See offsetSet

public function offsetUnset( mixed $element ): void;
Offset to unset See offsetUnset

public function remove( string $element ): void;
Delete the element from the collection

public function serialize(): string;
String representation of object See serialize

public function set( string $element, mixed $value ): void;
Set an element in the collection

public function toArray(): array;
Returns the object in an array format

public function toJson( int $options = int ): string;
Returns the object in a JSON format

The default string uses the following options for json_encode

JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES

See rfc4627

public function unserialize( mixed $serialized ): void;
Constructs the object See unserialize

protected function setData( string $element, mixed $value ): void;
Internal method to set data

Collection\CollectionInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Collection
  • Uses

  • Extends

  • Implements

Phalcon\Collection\CollectionInterface

Interface for Phalcon\Collection class

Methods

public function __get( string $element ): mixed;
public function __isset( string $element ): bool;
public function __set( string $element, mixed $value ): void;
public function __unset( string $element ): void;
public function clear(): void;
public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
public function getKeys( bool $insensitive = bool ): array;
public function getValues(): array;
public function has( string $element ): bool;
public function init( array $data = [] ): void;
public function remove( string $element ): void;
public function set( string $element, mixed $value ): void;
public function toArray(): array;
public function toJson( int $options = int ): string;

Collection\Exception

Source on GitHub

  • Namespace

    • Phalcon\Collection
  • Uses

    • Throwable
  • Extends

    \Exception

  • Implements

Exceptions for the Collection object

Collection\ReadOnly

Source on GitHub

  • Namespace

    • Phalcon\Collection
  • Uses

    • Phalcon\Collection
  • Extends

    Collection

  • Implements

A read only Collection object

Methods

public function remove( string $element ): void;
Delete the element from the collection

public function set( string $element, mixed $value ): void;
Set an element in the collection