PHPackages                             petrenkoanton/php-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. petrenkoanton/php-collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

petrenkoanton/php-collection
============================

Custom collection implementation

v1.1.2(2y ago)16021MITPHPPHP ^8.0

Since Jan 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PetrenkoAnton/php-collection)[ Packagist](https://packagist.org/packages/petrenkoanton/php-collection)[ RSS](/packages/petrenkoanton-php-collection/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (8)Dependencies (6)Versions (10)Used By (1)

php-collection
==============

[](#php-collection)

[![PHP Version](https://camo.githubusercontent.com/7d20e207625b995e892a4d6a7aae449027a49cb3faaf596d941e052e0a75acc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e)](https://packagist.org/packages/petrenkoanton/php-collection)[![Latest Version on Packagist](https://camo.githubusercontent.com/ece9e052afa4fa719836c037c0e3e5ea6524b43c55bd2eae068482c640f04b75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e2e737667)](https://packagist.org/packages/petrenkoanton/php-collection)[![Total Downloads](https://camo.githubusercontent.com/62a829e87b92326ef605dc62209be0085dd116e1f50c19b5a4e5f46d8f26fbab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e2e737667)](https://packagist.org/packages/petrenkoanton/php-collection)[![License](https://camo.githubusercontent.com/422a95c565a4bc40e351ea19c94caa91ceee17a8e9fd69a6fc53ae93cf6fb577/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e)](https://packagist.org/packages/petrenkoanton/php-collection)

[![PHP Composer](https://github.com/PetrenkoAnton/php-collection/actions/workflows/tests.yml/badge.svg)](https://github.com/PetrenkoAnton/php-collection/actions/workflows/tests.yml)[![Coverage Status](https://camo.githubusercontent.com/48930396f46c0452d77671972839409868be52eb93097b759fde25d33567b9cb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f50657472656e6b6f416e746f6e2f7068702d636f6c6c656374696f6e2f62616467652e737667)](https://coveralls.io/github/PetrenkoAnton/php-collection)[![type-coverage](https://camo.githubusercontent.com/a14e9c50526dc64e2ca830be4b990b1bb1d1a9819b2bb69994f53a95c23b5ebe/68747470733a2f2f73686570686572642e6465762f6769746875622f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e2f636f7665726167652e737667)](https://shepherd.dev/github/petrenkoanton/php-collection)[![psalm-level](https://camo.githubusercontent.com/2bf193a3308312b1285276811c7ceeedd9c6ba8334c4900bcd1a140d4b3f6e9e/68747470733a2f2f73686570686572642e6465762f6769746875622f70657472656e6b6f616e746f6e2f7068702d636f6c6c656374696f6e2f6c6576656c2e737667)](https://shepherd.dev/github/petrenkoanton/php-collection)[![Build Status](https://github.com/petrenkoanton/php-collection/workflows/coding-style/badge.svg)](https://github.com/petrenkoanton/php-collection/actions)

[Installation](#installation) | [Functionality](#functionality) | [Usage](#usage) | [For developers](#for-developers) | [License](#license) | [Related projects](#related-projects)

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- php 8.0 or higher

### Composer

[](#composer)

```
composer require petrenkoanton/php-collection
```

Functionality
-------------

[](#functionality)

### Public methods

[](#public-methods)

#### [Collection](./src/Collection.php)

[](#collection)

MethodException\_\_construct(Collectable ...$items)-add(Collectable $item): voidInvalidItemTypeException | InvalidConstructorDeclarationExceptionfilter(callable $callback): Collection-getItems(): array-getItem(int $key): CollectableInvalidKeyExceptionfirst(): CollectableInvalidKeyExceptioncount(): int-### Exceptions

[](#exceptions)

Main library exception is [CollectionException](./src/Exception/CollectionException.php).

CodeMessage patternExceptionParent100Collection: %s | Expected item type: %s | Given: %sInvalidItemTypeExceptionCollectionException101Collection: %s | Err: Invalid constructor declarationInvalidConstructorDeclarationExceptionCollectionException200Collection: %s | Invalid key: %dInvalidKeyExceptionCollectionExceptionUsage
-----

[](#usage)

```
