PHPackages                             rinimisini/php-utilities - 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. rinimisini/php-utilities

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

rinimisini/php-utilities
========================

PHP implementation of different JavaScript built-in classes

v1.0.2(1y ago)04MITPHPPHP ^8.0

Since Sep 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/RiniMisini12/php-utilities)[ Packagist](https://packagist.org/packages/rinimisini/php-utilities)[ RSS](/packages/rinimisini-php-utilities/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

PHP Utilities
=============

[](#php-utilities)

PHP Utilities is a PHP library that provides implementations of various JavaScript built-in classes like `Set`, `Map`, and others. This library allows PHP developers to work with similar functionality found in JavaScript, but adapted for PHP environments.

Features
--------

[](#features)

- **Set Class**: A PHP implementation of JavaScript's `Set` class, providing methods for adding unique elements, deleting elements, performing set operations (union, intersection, and difference), and more.
- Future updates will include more classes such as:
    - **Map**
    - **WeakSet**
    - **WeakMap**

Requirements
------------

[](#requirements)

- **PHP**: ^8.0

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

[](#installation)

You can install this package via Composer:

```
composer require rinimisini/php-utilities
```

Usage
-----

[](#usage)

### Set Class

[](#set-class)

The Set class behaves similarly to JavaScript's Set. It allows storing unique elements and provides methods to perform common set operations.

#### Creating a Set

[](#creating-a-set)

```
$set = new Set();
```

#### Adding Elements to the Set

[](#adding-elements-to-the-set)

```
$set->add(1);
$set->add(2);
$set->add(3);
```

#### Checking if an Element Exists

[](#checking-if-an-element-exists)

```
if ($set->has(2)) {
echo "Set contains 2";
}
```

#### Deleting an Element

[](#deleting-an-element)

```
$set->delete(2);
```

#### Clearing the Set

[](#clearing-the-set)

```
$set->clear();
```

#### Getting the Set Size

[](#getting-the-set-size)

```
echo $set->size();  // Outputs the number of elements in the set
```

### Set Operations

[](#set-operations)

The Set class supports common set operations like union, intersection, and difference.

#### Union

[](#union)

```
$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$unionSet = $set1->union($set2);  // $unionSet contains [1, 2, 3]
```

#### Intersection

[](#intersection)

```
$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$intersectionSet = $set1->intersection($set2);  // $intersectionSet contains [2]
```

#### Difference

[](#difference)

```
$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$differenceSet = $set1->difference($set2);  // $differenceSet contains [1]
```

#### Iterating Over the Set

[](#iterating-over-the-set)

```
foreach ($set as $item) {
echo $item;
}
```

#### Serialization

[](#serialization)

```
$set = new Set();
$set->add(1)->add(2);

$serialized = serialize($set);
$unserializedSet = unserialize($serialized);
```

Map Class
---------

[](#map-class)

The Map class behaves similarly to JavaScript's Map. It allows storing key-value pairs where keys can be of any type, including objects.

### Creating a Map

[](#creating-a-map)

```
$map = new Map();
```

#### Setting Key-Value Pairs

[](#setting-key-value-pairs)

```
$map->set('name', 'Alice');
$map->set('age', 30);
```

#### Retrieving Values

[](#retrieving-values)

```
echo $map->get('name');  // Outputs: Alice
```

#### Checking if a Key Exists

[](#checking-if-a-key-exists)

```
if ($map->has('age')) {
echo "Age is set in the map.";
}
```

#### Deleting an Entry

[](#deleting-an-entry)

```
$map->delete('age');  // Removes the entry with key 'age'
```

#### Iterating Over the Map

[](#iterating-over-the-map)

```
foreach ($map as [$key, $value]) {
echo "Key: $key, Value: $value\n";
}
```

#### Using forEach

[](#using-foreach)

```
$map->forEach(function ($value, $key) {
echo "Key: $key, Value: $value\n";
});
```

#### Retrieving Keys and Values

[](#retrieving-keys-and-values)

```
$keys = $map->keys();     // Returns an array of keys
$values = $map->values(); // Returns an array of values
```

#### Clearing the Map

[](#clearing-the-map)

```
$map->clear();
```

WeakSet Class
-------------

[](#weakset-class)

The WeakSet class allows storing objects weakly, meaning they will be garbage collected when no other references exist.

#### Creating a WeakSet

[](#creating-a-weakset)

```
$weakSet = new WeakSet();
```

#### Adding Objects to the WeakSet

[](#adding-objects-to-the-weakset)

```
$obj = new stdClass();
$weakSet->add($obj);
```

#### Checking if an Object Exists

[](#checking-if-an-object-exists)

```
if ($weakSet->has($obj)) {
echo "Object exists in the WeakSet";
}
```

#### Removing an Object

[](#removing-an-object)

```
$weakSet->delete($obj);
```

#### Clearing the WeakSet

[](#clearing-the-weakset)

```
$weakSet->clear();
```

#### Iterating Over the WeakSet

[](#iterating-over-the-weakset)

```
foreach ($weakSet as $object) {
echo get_class($object);
}
```

Future Plans
------------

[](#future-plans)

#### The current release includes JavaScript-inspired classes such as:

[](#the-current-release-includes-javascript-inspired-classes-such-as)

- Map: A collection of key-value pairs with unique keys.
- WeakSet: A collection that stores objects weakly, allowing them to be garbage collected if no other references exist.

### Future releases may include additional JavaScript-inspired classes such as:

[](#future-releases-may-include-additional-javascript-inspired-classes-such-as)

- WeakMap: A collection of key-value pairs where the keys are objects and references are weak.

Contributing
------------

[](#contributing)

Contributions are welcome! If you'd like to contribute, feel free to open a pull request or submit issues for features and bug reports.

### Steps to Contribute

[](#steps-to-contribute)

1. Fork this repository.
2. Create a new feature branch: `git checkout -b feature/my-feature`.
3. Commit your changes: `git commit -m 'Add some feature'`.
4. Push the branch: `git push origin feature/my-feature`.
5. Open a Pull Request.

License
-------

[](#license)

This project is licensed under the **MIT** License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.9% 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 ~0 days

Total

3

Last Release

601d ago

### Community

Maintainers

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

---

Top Contributors

[![rinimisini](https://avatars.githubusercontent.com/u/165013573?v=4)](https://github.com/rinimisini "rinimisini (10 commits)")[![RiniMisini12](https://avatars.githubusercontent.com/u/147084973?v=4)](https://github.com/RiniMisini12 "RiniMisini12 (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rinimisini-php-utilities/health.svg)

```
[![Health](https://phpackages.com/badges/rinimisini-php-utilities/health.svg)](https://phpackages.com/packages/rinimisini-php-utilities)
```

###  Alternatives

[beyondcode/laravel-comments

Add comments to your Laravel application

605414.2k2](/packages/beyondcode-laravel-comments)[graphp/graph

GraPHP is the mathematical graph/network library written in PHP.

711292.6k3](/packages/graphp-graph)[kucrut/vite-for-wp

Vite integration for WordPress plugins and themes development.

321127.6k6](/packages/kucrut-vite-for-wp)[cijic/phpmorphy

phpMorphy - morphological analyzer library for Russian, English, German and Ukrainian languages.

115339.9k7](/packages/cijic-phpmorphy)[alrik11es/cowsayphp

Cowsay port in PHP

72516.3k1](/packages/alrik11es-cowsayphp)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)

PHPackages © 2026

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