PHPackages                             rotexsoft/versatile-collections - 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. rotexsoft/versatile-collections

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

rotexsoft/versatile-collections
===============================

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

7.0.1(5mo ago)186.0k7[13 issues](https://github.com/rotexsoft/versatile-collections/issues)1BSD-3-ClausePHPPHP &gt;=8.2.0CI passing

Since May 6Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/rotexsoft/versatile-collections)[ Packagist](https://packagist.org/packages/rotexsoft/versatile-collections)[ Docs](https://github.com/rotexsoft/versatile-collections)[ RSS](/packages/rotexsoft-versatile-collections/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (38)Used By (1)

Versatile Collections
=====================

[](#versatile-collections)

[![PHP Tests and Code Quality Tools](https://github.com/rotexsoft/versatile-collections/workflows/Run%20PHP%20Tests%20and%20Code%20Quality%20Tools/badge.svg)](https://github.com/rotexsoft/versatile-collections/actions) [![Packagist Version](https://camo.githubusercontent.com/ee64619a798b7e8ae1077c89c69707bb8312428a4c99f8ce1868725e134563ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://github.com/rotexsoft/versatile-collections/releases/latest) [![GitHub](https://camo.githubusercontent.com/e5c446f6b58eebd7746a92e20467c2b2b9153e3feba41013474c0b4a0e3ee5c1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://github.com/rotexsoft/versatile-collections/blob/master/LICENSE) [![Coveralls branch](https://camo.githubusercontent.com/4194b7788ab9a0f5c0f6c535d7dfcc542afdd83cde091591bba5cf8562c77850/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e732f6d6173746572)](https://coveralls.io/github/rotexsoft/versatile-collections?branch=master) [![GitHub code size in bytes](https://camo.githubusercontent.com/18035830db757dfe3080a65e96e936251c518e58ce462f7c64c1447864cb6a84/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/18035830db757dfe3080a65e96e936251c518e58ce462f7c64c1447864cb6a84/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73) [![Packagist Downloads](https://camo.githubusercontent.com/36ec4253d8afa56b0777e7682d29c307765a4249fc30fccda373af4d3dbf305f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/36ec4253d8afa56b0777e7682d29c307765a4249fc30fccda373af4d3dbf305f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73) [![GitHub top language](https://camo.githubusercontent.com/c763dca287006377f573c733c3fe7e3067ab9e19650411d3d9f594b5cd95affc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/c763dca287006377f573c733c3fe7e3067ab9e19650411d3d9f594b5cd95affc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73) [![Packagist PHP Version Support](https://camo.githubusercontent.com/f54ea9d45bc5e8ac1fd5651f55ba7ed3cadcbedc0e09f922ccefe79469e1ea67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/f54ea9d45bc5e8ac1fd5651f55ba7ed3cadcbedc0e09f922ccefe79469e1ea67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73) [![GitHub commits since latest release (by date) for a branch](https://camo.githubusercontent.com/1ee7807212caec90cb209e6a6c527f61b2bdcaac57994d58dd822c2100b9629c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e732f6c61746573742f6d6173746572)](https://camo.githubusercontent.com/1ee7807212caec90cb209e6a6c527f61b2bdcaac57994d58dd822c2100b9629c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e732f6c61746573742f6d6173746572) [![GitHub last commit (branch)](https://camo.githubusercontent.com/cab26a24b9383a1b752b36a9e14dd296eb3b02e83de62f052e2866f041e3e315/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e732f6d6173746572)](https://camo.githubusercontent.com/cab26a24b9383a1b752b36a9e14dd296eb3b02e83de62f052e2866f041e3e315/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e732f6d6173746572) [![GitHub Release Date](https://camo.githubusercontent.com/bb61d7c7dc1f3716f6b99002d626071778d9571e1526e0ba174c4014ba93e5f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/bb61d7c7dc1f3716f6b99002d626071778d9571e1526e0ba174c4014ba93e5f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73) [![Libraries.io dependency status for GitHub repo](https://camo.githubusercontent.com/0882e857795a7058a55b2f55a968ee77120b0bc86ccbf805ca63f6fc1331e84c/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f726f746578736f66742f766572736174696c652d636f6c6c656374696f6e73)](https://libraries.io/packagist/rotexsoft%2Fversatile-collections)

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

You can:

- use one of the provided Collection classes directly in your application(s)
- or include one or more of the provided Collection classes within an existing class in your application and expose features you want (Composition)
- or extend one or more of the the provided Collection classes (Inheritance) and then use those extended classes in your application(s)
- or just implement one or more of the Collection Interfaces and use the corresponding trait (Contract fulfillment)

This package provides optional strict-typing of collection items and strives for 100 % unit-test coverage.

[![Collection Classes](versatile-collections.svg)](versatile-collections.svg)

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

[](#installation)

**Via composer:** (Requires PHP 7.4+ or PHP 8.0+).

Switch to the 3.X branch to read the documentation for the 3.X version.

Switch to the 4.X branch to read the documentation for the 4.X version.

Switch to the 5.x branch to read the documentation for the 5.x version.

Switch to the 6.x branch to read the documentation for the 6.x version.

Switch to the master branch to read the documentation for the latest version.

```
composer require rotexsoft/versatile-collections

```

Basics
------

[](#basics)

If you are simply looking to store items of the same or differing types in a collection you can use simply use the **GenericCollection** class like so:

```
