PHPackages                             mvccore/ext-tool-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. [Framework](/categories/framework)
4. /
5. mvccore/ext-tool-collections

ActiveLibrary[Framework](/categories/framework)

mvccore/ext-tool-collections
============================

MvcCore - Extension - Tool - Collections - extension with collection classes for typed arrays in PHP.

v5.3.0(1y ago)03222BSD-3-ClausePHPPHP &gt;=5.4.0

Since May 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mvccore/ext-tool-collections)[ Packagist](https://packagist.org/packages/mvccore/ext-tool-collections)[ RSS](/packages/mvccore-ext-tool-collections/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (2)

MvcCore - Extension - Tool - Collections
========================================

[](#mvccore---extension---tool---collections)

[![Latest Stable Version](https://camo.githubusercontent.com/6a0e9e7da98c52006afe617f10a93df0da2dce64b73eedf5b9b3fcee6bfb6039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461626c652d76352e332e302d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://github.com/mvccore/ext-tool-collections/releases)[![License](https://camo.githubusercontent.com/53baed538c1c87a033a212f6f4acce684d36137f8622307643ab25e08118452e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d425344253230332d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://mvccore.github.io/docs/mvccore/5.0.0/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/9e923690739211296a00adce5d359999dfa345f80fc1b2e2cfe72c49523ee334/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d352e342d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://camo.githubusercontent.com/9e923690739211296a00adce5d359999dfa345f80fc1b2e2cfe72c49523ee334/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d352e342d627269676874677265656e2e7376673f7374796c653d706c6173746963)

Collection classes for typed arrays in PHP.

Be careful, in places, where is necessary to process large arrays very fast,
use arrays instead. This extensions are only for comfortable coding where
you have enough execution time or where time is not so critical.

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

[](#installation)

```
composer require mvccore/ext-tool-collections
```

Usage
-----

[](#usage)

First, le'ts say we have defined collection item class like this:

```
class MyItem {
	public function __construct (protected string $name) {}
	public function GetName (): string {
		return $this->name;
	}
}
```

To have automatically typed collection items
in for or foreach loops like this, without PHPDocs code:

```
$myItemsSet = new MyItemsSet([
	new MyItem('John'),
	new MyItem('Joe'),
]);
$myItemsMap = new MyItemsMap([
	'john'	=> new MyItem('John'),
	'joe'	=> new MyItem('Joe'),
]);
for ($i = 0, $l = count($myItemsSet); $i < $l; $i++) {
	$myItem = $myItemsSet[$i];
	// now `$myItem` local variable is automatically
	// typed by your IDE as `MyItem`, the method
	// `GetName()` is always autocompleted by your IDE:
	echo $myItem->GetName();
}
foreach ($myItemsMap as $myItem) {
	// now `$myItem` local variable is automatically
	// typed by your IDE as `MyItem`, the method
	// `GetName()` is always autocompleted by your IDE:
	echo $myItem->GetName();
}
```

For sequence collection, you need to create:

- empty class extended from `\MvcCore\Ext\Tools\Collections\Set`
- go to extended class and copy paste commented template methods into empty class
- uncomment all template methods and replace all mixed types with final type (`MyItem`)

```
class MyItemsSet extends \MvcCore\Ext\Tools\Collections\Set {
	// all methods are copy pasted from extended class:
	public function current (): MyItem {
		$offsetInt = $this->keys[$this->position];
		return $this->array[$offsetInt];
	}
	/**
	 * @param  int    $offset
	 * @param  MyItem $value
	 */
	public function offsetSet ($offset, $value): void {
		if ($offset === NULL) {
			$this->array[] = $value;
		} else {
			$offsetInt = intval($offset);
			$this->array[$offsetInt] = $value;
		}
		$this->keys = array_keys($this->array);
		$this->count = count($this->array);
	}
	/** @param int $offset */
	public function offsetGet ($offset): MyItem {
		$offsetInt = intval($offset);
		return array_key_exists($offsetInt, $this->array)
			? $this->array[$offsetInt]
			: null;
	}
	public function shift (): MyItem {
		$offsetInt = array_shift($this->keys);
		$value = $this->array[$offsetInt];
		unset($this->array[$offsetInt]);
		$this->count -= 1;
		if ($this->position === $this->count)
			$this->position--;
		return $value;
	}
	/**
	 * @param MyItem $values,...
	 */
	public function unshift (): int {
		$args = func_get_args();
		$argsCnt = count($args);
		array_unshift($args, $this->array);
		$this->count = call_user_func_array('array_unshift', $args);
		$this->keys = array_keys($this->array);
		if ($this->position > 0)
			$this->position += $argsCnt;
		return $this->count;
	}
}
```

For associative collection, you need to create:

- empty class extended from `\MvcCore\Ext\Tools\Collections\Map`
- go to extended class and copy paste commented template methods into empty class
- uncomment all template methods and replace all mixed types with final type (`MyItem`)

```
class MyItemsMap extends \MvcCore\Ext\Tools\Collections\Map {
	// all methods are copy pasted from extended class:
		public function current (): MyItem {
		$key = $this->keys[$this->position];
		return $this->array[$key];
	}
	/**
	 * @param string $offset
	 * @param MyItem  $value
	 */
	public function offsetSet ($offset, $value): void {
		if ($offset === NULL) {
			$this->array[] = $value;
		} else {
			$offsetStr = (string) $offset;
			$this->array[$offsetStr] = $value;
		}
		$this->keys = array_keys($this->array);
		$this->count = count($this->array);
	}
	/** @param string $offset */
	public function offsetGet ($offset): MyItem {
		$offsetStr = (string) $offset;
		return array_key_exists($offsetStr, $this->array)
			? $this->array[$offsetStr]
			: null;
	}
	public function shift (): MyItem {
		$offsetStr = array_shift($this->keys);
		$value = $this->array[$offsetStr];
		unset($this->array[$offsetStr]);
		$this->count -= 1;
		if ($this->position === $this->count)
			$this->position--;
		return $value;
	}
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance40

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~307 days

Total

4

Last Release

533d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a68d9cd696ed584a9ee742fa089d0650f4f7a95754bf5d9ee301e6c9013df3fd?d=identicon)[tomFlidr](/maintainers/tomFlidr)

---

Top Contributors

[![tomFlidr](https://avatars.githubusercontent.com/u/1833722?v=4)](https://github.com/tomFlidr "tomFlidr (10 commits)")

---

Tags

pluginframeworkarraytoolvectormapsetcollectionlistmvcextensionplug-indictionaryexttypedmvccore

### Embed Badge

![Health badge](/badges/mvccore-ext-tool-collections/health.svg)

```
[![Health](https://phpackages.com/badges/mvccore-ext-tool-collections/health.svg)](https://phpackages.com/packages/mvccore-ext-tool-collections)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
