PHPackages                             florianwolters/component-core-hashcode - 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. florianwolters/component-core-hashcode

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

florianwolters/component-core-hashcode
======================================

Provides a hash code value for objects as a PHP component.

v0.3.0(11y ago)18581LGPL-3.0+PHPPHP &gt;=5.4

Since Sep 24Pushed 11y ago1 watchersCompare

[ Source](https://github.com/FlorianWolters/PHP-Component-Core-HashCode)[ Packagist](https://packagist.org/packages/florianwolters/component-core-hashcode)[ Docs](http://github.com/FlorianWolters/PHP-Component-Core-HashCode)[ RSS](/packages/florianwolters-component-core-hashcode/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (9)Versions (5)Used By (1)

Component\\Core\\HashCode
=========================

[](#componentcorehashcode)

**Component\\Core\\HashCode** is a simple-to-use [PHP](https://php.net "PHP: Hypertext Preprocessor") component that provides a hash code value for objects.

[![Build Status](https://camo.githubusercontent.com/ea27b77c052d1ce39af3c579be6a12edbf30e155e34ea4fbb9f5dfde744bc3ad/68747470733a2f2f7472617669732d63692e6f72672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d48617368436f64652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/FlorianWolters/PHP-Component-Core-HashCode)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/499a2204a7e8325453e302d48a1e1ed697e2dee5a031afc1a7b659cc026cd37f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d48617368436f64652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Core-HashCode/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b43b0736f7de03e4f460ed06b4ae1625b2b07c81c6eff6cdf0b76a2ce215455f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d48617368436f64652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Core-HashCode/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/fd1529aaf9219f43d789008c8793bc9d3068f52a3b47bd0aaf47319842941834/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38613033626164662d333934622d343334662d613136392d6239633663333534376265372f6d696e692e706e67)](https://insight.sensiolabs.com/projects/8a03badf-394b-434f-a169-b9c6c3547be7)[![Coverage Status](https://camo.githubusercontent.com/f99e2d889411239d75143115e0c78139bca65a0e41681668c6aa216066bda893/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d48617368436f64652e737667)](https://coveralls.io/r/FlorianWolters/PHP-Component-Core-HashCode?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/67c6ef17a23b4cbaa1de2614a7d18909df900a66d5fc1c045b747392b58ea6d4/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f762f737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)[![Total Downloads](https://camo.githubusercontent.com/b6f43c03243599137ef4b7063b8200c7dc0c46109e8e2dbf5229c84158f4733a/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)[![Monthly Downloads](https://camo.githubusercontent.com/37aa220c5b029ff17933bbb12eeea063ed4e39758f3ad7597da3bf18fd821fa0/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f642f6d6f6e74686c792e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)[![Daily Downloads](https://camo.githubusercontent.com/5fa32b77d50f37e154b2efc0233d5ead2aa2a16750d9c82c42c3abb682c0739a/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f642f6461696c792e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)[![Latest Unstable Version](https://camo.githubusercontent.com/8f458d5362d8183db9fba318ce10a50a7389e3f5a5bf7325650fa34dc4da91c6/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f762f756e737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)[![License](https://camo.githubusercontent.com/cb9f17964b4504f06a85f8754399dc0f7a61795f61f8b240a1241a481e215998/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652f6c6963656e73652e706e67)](https://packagist.org/packages/florianwolters/component-core-hashcode)

[![Stories in Ready](https://camo.githubusercontent.com/64ba1a6a554ec47dd4c994c762e43102ab8e37152c3625e44497b5a8e988d9b3/68747470733a2f2f62616467652e776166666c652e696f2f666c6f7269616e776f6c746572732f7068702d636f6d706f6e656e742d636f72652d68617368636f64652e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/florianwolters/php-component-core-hashcode)[![Dependency Status](https://camo.githubusercontent.com/562a44d01c57d0b8899dc3b862c5be7ceb54eca3109c259ea14e98cbc49ef0e3/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3531633333306666303037666364303030323030303433372f62616467652e737667)](https://www.versioneye.com/user/projects/51c330ff007fcd0002000437)[![Dependencies Status](https://camo.githubusercontent.com/9268807b7201b01b9eb706d2f41dbb3650b52aa8b39a64bedaef76e35ecb991e/68747470733a2f2f646570656e64696e672e696e2f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d48617368436f64652e706e67)](http://depending.in/FlorianWolters/PHP-Component-Core-HashCode)[![HHVM Status](https://camo.githubusercontent.com/750a0d8d4484d0de255e747ba80cde97e40615e998aa1c52b1f7526ecb4275cb/687474703a2f2f6868766d2e683463632e64652f62616467652f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d68617368636f64652e706e67)](http://hhvm.h4cc.de/package/florianwolters/component-core-hashcode)

Table of Contents (ToC)
-----------------------

[](#table-of-contents-toc)

- [Introduction](#introduction)
- [Features](#features)
- [Requirements](#requirements)
- [Usage](#usage)
- [Installation](#installation)
- [Testing](#testing)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Introduction
------------

[](#introduction)

This component is inspired by the method [`java.lang.Object.hashCode`](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode() "Object (Java Platform SE 7)") of the [Java](http://java.com "Java") programming language.

**Component\\Core\\HashCode** consists of two artifacts:

1. The interface [`FlorianWolters\Component\Core\HashCodeInterface`](src/main/php/HashCodeInterface.php "FlorianWolters\Component\Core\HashCodeInterface"): Indicates that an implementing class provides a hash code value for objects.
2. The trait [`FlorianWolters\Component\Core\HashCodeTrait`](src/main/php/HashCodeTrait.php "FlorianWolters\Component\Core\HashCodeTrait"): Provides a default hash code value implementation for objects.

Features
--------

[](#features)

- Offers a default hash code value implementation for objects via the method `hashCode` of the trait [`HashCodeTrait`](src/main/php/HashCodeTrait.php "FlorianWolters\Component\Core\HashCodeTrait"). Refer to the section [Usage](#using-the-default-implementation) below for an example.
- Allows to create a custom hash code value implementation by implementing the interface [`HashCodeInterface`](src/main/php/HashCodeInterface.php "FlorianWolters\Component\Core\HashCodeInterface"), more precisely implementing the public method `hashCode` of that interface. Refer to the section [Usage](#using-a-custom-implementation) below for an example.
- Artifacts tested with both static and dynamic test procedures:
    - Dynamic component tests (unit and integration tests) implemented with [PHPUnit](https://phpunit.de "PHPUnit").
    - Static code analysis performed using the following tools:
        - [PHP\_CodeSniffer](https://pear.php.net/package/PHP_CodeSniffer "PHP_CodeSniffer"): Style Checker
        - [PHP Mess Detector (PHPMD)](http://phpmd.org "PHPMD - PHP Mess Detector"): Code Analyzer
        - [PHP Depend](http://pdepend.org "PHP Depend - Software Metrics for PHP"): Code Metrics
        - [phpcpd](https://github.com/sebastianbergmann/phpcpd "sebastianbergmann/phpcpd · GitHub"): Copy/Paste Detector (CPD)
        - [phpdcd](https://github.com/sebastianbergmann/phpdcd "sebastianbergmann/phpdcd · GitHub"): Dead Code Detector (DCD)
        - [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker "SensioLabs Security Checker"): Security Checker
    - Continuous Integration (CI) using the following web services:
        - [Scrutinizer CI](https://scrutinizer-ci.com "Scrutinizer CI")
        - [SensioLabsInsight](https://insight.sensiolabs.com "SensioLabsInsight")
        - [Coveralls](https://coveralls.io "Coveralls")
        - [VersionEye](https://versioneye.com "VersionEye")
        - [Depending](https://depending.in "Depending")
        - [Waffle](https://waffle.io "Waffle")
- Provides a [Packagist](https://packagist.org "Packagist") package which can be installed using the dependency manager [Composer](https://getcomposer.org "Composer"). Click [here](https://packagist.org/packages/florianwolters/component-core-hashcode "florianwolters/component-core-hashcode - Packagist") for the package on [Packagist](https://packagist.org "Packagist").
- Provides a complete Application Programming Interface (API) documentation generated with the documentation generator [Sami](https://github.com/fabpot/sami "fabpot/sami · GitHub"). Click [here](http://blog.florianwolters.de/PHP-Component-Core-HashCode "Application Programming Interface (API) documentation") for the API documentation.
- Follows the following "standards" from the [PHP Framework Interoperability Group (FIG)](http://php-fig.org "PHP-FIG — PHP Framework Interop Group"). PSR stands for PHP Standards Recommendation:
    - [PSR-0](http://php-fig.org/psr/psr-0 "PSR-0 requirements for autoloader interoperability"): Autoloading Standards

        > Aims to provide a standard file, class and namespace convention to allow plug-and-play code.
    - [PSR-1](http://php-fig.org/psr/psr-1 "PSR-1 basic coding style guide"): Basic Coding Standard

        > Aims to ensure a high level of technical interoperability between shared PHP code.
    - [PSR-2](http://php-fig.org/psr/psr-2 "PSR-2 coding style guide"): Coding Style Guide

        > Provides a Coding Style Guide for projects looking to standardize their code.
    - [PSR-4](http://php-fig.org/psr/psr-4 "PSR-4: Improved Autoloading"): Autoloader

        > A more modern take on autoloading reflecting advances in the ecosystem.
- Follows the [Semantic Versioning](http://semver.org "Semantic Versioning") (SemVer) specification version 2.0.0.

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

[](#requirements)

### Production

[](#production)

- [PHP](https://php.net "PHP: Hypertext Preprocessor") &gt;= 5.4
- [Composer](https://getcomposer.org "Composer")

### Development

[](#development)

- [PHPUnit](https://phpunit.de "PHPUnit")
- [phpcpd](https://github.com/sebastianbergmann/phpcpd "sebastianbergmann/phpcpd · GitHub")
- [phpdcd](https://github.com/sebastianbergmann/phpdcd "sebastianbergmann/phpdcd · GitHub")
- [PHP\_CodeSniffer](https://pear.php.net/package/PHP_CodeSniffer "PHP_CodeSniffer")
- [PHP Mess Detector (PHPMD)](http://phpmd.org "PHPMD - PHP Mess Detector")
- [Sami](https://github.com/fabpot/sami "fabpot/sami · GitHub")
- [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker "SensioLabs Security Checker")
- [php-coveralls](https://github.com/satooshi/php-coveralls "satooshi/php-coveralls · GitHub")

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

[](#installation)

**Component\\Core\\HashCode** should be installed using the dependency manager [Composer](https://getcomposer.org "Composer").

> [Composer](https://getcomposer.org "Composer") is a tool for dependency management in [PHP](https://php.net "PHP: Hypertext Preprocessor"). It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

The [Composer](https://getcomposer.org "Composer") installer can be downloaded with `php`.

```
php -r "readfile('https://getcomposer.org/installer');" | php

```

> This will just check a few [PHP](https://php.net "PHP: Hypertext Preprocessor") settings and then download `composer.phar`to your working directory. This file is the [Composer](https://getcomposer.org "Composer") binary. It is a PHAR ([PHP](https://php.net "PHP: Hypertext Preprocessor") archive), which is an archive format for [PHP](https://php.net "PHP: Hypertext Preprocessor") which can be run on the command line, amongst other things.

> To resolve and download dependencies, run the `install` command:

```
php composer.phar install

```

If you are creating a component that relies on **Component\\Core\\HashCode**, please make sure that you add **Component\\Core\\HashCode** to your component's `composer.json` file:

```
{
    "require": {
        "florianwolters/component-core-hashcode": "0.3.*"
    }
}
```

Usage
-----

[](#usage)

The best documentation for **Component\\Core\\HashCode** are the unit tests, which are shipped in the package.

The most important usage rule:

> Always implement the interface [`HashCodeInterface`](src/main/php/HashCodeInterface.php "FlorianWolters\Component\Core\HashCodeInterface") if using the trait [`HashCodeTrait`](src/main/php/HashCodeTrait.php "FlorianWolters\Component\Core\HashCodeTrait"), since that allows [Type Hinting](https://php.net/language.oop5.typehinting "PHP: Type Hinting - Manual").

The class [`HashCodeExample`](resources/php/HashCodeExample.php "FlorianWolters\Example\HashCodeExample") can be run via the command `php resources/php/HashCodeExample.php` from the root of the project.

### Default Hash Code

[](#default-hash-code)

The class [`HashCodeDefaultImpl`](src/test/resources/HashCodeDefaultImpl.php.php "FlorianWolters\Example\HashCodeDefaultImpl.php") uses the default implementation of the trait [`HashCodeTrait`](src/main/php/HashCodeTrait.php "FlorianWolters\Component\Core\HashCodeTrait"). The trait uses the global function [`spl_object_hash`](https://php.net/function.spl-object-hash "PHP: spl_object_hash - Manual") to calculate the hash code for the object.

### Custom Hash Code

[](#custom-hash-code)

The class [`HashCodeCustomImpl`](src/test/resources/HashCodeCustomImpl.php.php "FlorianWolters\Example\HashCodeCustomImpl.php") implements a custom implementation, which fulfills the design contract for a *Value Object*. The value of the object is used to calculate the hash code for the object.

Testing
-------

[](#testing)

```
phpunit

```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Florian Wolters](https://github.com/FlorianWolters "FlorianWolters · GitHub")
- [All Contributors](https://github.com/FlorianWolters/PHP-Component-Core-HashCode/contributors "Contributors to FlorianWolters/PHP-Component-Core-HashCode")

License
-------

[](#license)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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 ~217 days

Total

4

Last Release

4334d ago

PHP version history (2 changes)v0.1.0-betaPHP &gt;=5.3.0

v0.2.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/75dd7e42d69a87c4a0c68b4f29f5d223eb1f9a3f647abafa72da80d2a06d2442?d=identicon)[FlorianWolters](/maintainers/FlorianWolters)

---

Top Contributors

[![FlorianWolters](https://avatars.githubusercontent.com/u/1318837?v=4)](https://github.com/FlorianWolters "FlorianWolters (37 commits)")

---

Tags

languageobjecthashcorehash code

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/florianwolters-component-core-hashcode/health.svg)

```
[![Health](https://phpackages.com/badges/florianwolters-component-core-hashcode/health.svg)](https://phpackages.com/packages/florianwolters-component-core-hashcode)
```

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.4k48.6M278](/packages/hashids-hashids)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)

PHPackages © 2026

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