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

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

florianwolters/component-core-cloneable
=======================================

Allows and disallows the cloning of objects as a PHP component.

v0.2.0(13y ago)37141LGPL-3.0+PHPPHP &gt;=5.4

Since Feb 21Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (1)

Component\\Core\\Cloneable
==========================

[](#componentcorecloneable)

**FlorianWolters\\Component\\Core\\Cloneable** is a simple-to-use [PHP](https://php.net "PHP: Hypertext Preprocessor") component that allows and disallows the cloning of objects.

[![Build Status](https://camo.githubusercontent.com/1b4551c150b59f7e1726f25cc585bc61eff301fc757dba4dccf24e6c12718022/68747470733a2f2f7472617669732d63692e6f72672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436c6f6e6561626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/FlorianWolters/PHP-Component-Core-Cloneable)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d904a4ee59f7757fb44de78d81d83d685616009b92ad1c8d8f8bf2ec6a8fae75/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436c6f6e6561626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Core-Cloneable/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/3ccdd0b778290de592686447f920be3611742965a6fe9314cadb493e5952fc0f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436c6f6e6561626c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Core-Cloneable/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/e29c3c5f5b8d673c3ab7182f274535414eeeda7378ce42f2918ea6d7a64b6aec/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31363837383735392d656133652d343835342d626336342d6334333430326665303962632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/16878759-ea3e-4854-bc64-c43402fe09bc)[![Coverage Status](https://camo.githubusercontent.com/d454cc4dc37aefede7be19bfe134833c26b5b0ed2270b6a0544e499d3027f122/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436c6f6e6561626c652f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/FlorianWolters/PHP-Component-Core-Cloneable?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/54317ba8b90403aa05b5de3b85d1f39dd1d057be2c2fc92cfdcac509ccc3b670/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f762f737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)[![Total Downloads](https://camo.githubusercontent.com/895af22ee7f15a8fc4cf2794fb35dd90c357a0fd04138ed1f26c8b2dc35a263c/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)[![Monthly Downloads](https://camo.githubusercontent.com/8bb016a4ac908bddf2b84deb85c4daa4698eaa5a625286bff59a533b86cedc89/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f642f6d6f6e74686c792e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)[![Daily Downloads](https://camo.githubusercontent.com/fc8e8b7b9ba4e3cbac718f834f1a1ed8b642edb336cfe77e0e9d8be7c5079706/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f642f6461696c792e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)[![Latest Unstable Version](https://camo.githubusercontent.com/54ac23ce9f223c0304647faa71eaa6cbf182031cd0873f0c610dfa3b96a91c58/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f762f756e737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)[![License](https://camo.githubusercontent.com/39f18ccf2150fbdc11f4288235691b1817191fee813ea1bd6b092ec35666d3e3/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652f6c6963656e73652e706e67)](https://packagist.org/packages/florianwolters/component-core-cloneable)

[![Stories in Ready](https://camo.githubusercontent.com/8b423116066bd0dd408ef9edf7373595f04707f5c2c34a2ed784a7cc9c2bdcb5/68747470733a2f2f62616467652e776166666c652e696f2f666c6f7269616e776f6c746572732f7068702d636f6d706f6e656e742d636f72652d636c6f6e6561626c652e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/florianwolters/php-component-core-cloneable)[![Dependency Status](https://camo.githubusercontent.com/5bf7bbe2f74a6d43a64d45bd91964f26778ae6e18094dc29bfe4b59f1dc29612/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3531633333313032303037666364303030323030303433392f62616467652e706e67)](https://www.versioneye.com/user/projects/51c33102007fcd0002000439)[![Dependencies Status](https://camo.githubusercontent.com/02b90d0c497d371d00a1f012f356b93694e3c250aa30a5835062287cb8370eef/68747470733a2f2f646570656e64696e672e696e2f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436c6f6e6561626c652e706e67)](http://depending.in/FlorianWolters/PHP-Component-Core-Cloneable)[![HHVM Status](https://camo.githubusercontent.com/13ef3d31e043d15ed5f5e5686178f95e398941552d1f9f8e378ce137ba7f3d69/687474703a2f2f6868766d2e683463632e64652f62616467652f666c6f7269616e776f6c746572732f636f6d706f6e656e742d636f72652d636c6f6e6561626c652e706e67)](http://hhvm.h4cc.de/package/florianwolters/component-core-cloneable)

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

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

- [Introduction](#introduction)
- [Features](#features)
- [Requirements](#requirements)
- [Usage](#usage)
- [Installation](#installation)
- [As A Dependency On Your Component](#as-a-dependency-on-your-component)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#introduction)

This component is inspired by the the [Java](https://java.com "Java") programming language.

**FlorianWolters\\Component\\Core\\Cloneable** consists of six artifacts:

1. The interface [`FlorianWolters\Component\Core\CloneableInterface`](src/main/php/CloneableInterface.php "FlorianWolters\Component\Core\CloneableInterface"): Indicates to the magic [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") method of a class that it is legal for that method to make a field-for-field copy of instances of that class.
2. The exception class [`FlorianWolters\Component\Core\CloneNotSupportedException`](src/main/php/CloneNotSupportedException.php "FlorianWolters\Component\Core\CloneNotSupportedException"): Indicates that the magic [`__clone`](https://coveralls.io "Coveralls") method in a class has been called to clone an object, but that the object's class does not implement the [`CloneableInterface`](https://depending.in "Depending").
3. The trait [`FlorianWolters\Component\Core\CloneNotSupportedTrait`](src/main/php/CloneNotSupportedTrait.php "FlorianWolters\Component\Core\CloneNotSupportedTrait"): Indicates to the magic [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") method of a class that it is **illegal** for that method to make a field-for-field copy of instances of that class.
4. The trait [`FlorianWolters\Component\Core\ShallowCloneTrait`](src/main/php/ShallowCloneTrait.php "FlorianWolters\Component\Core\ShallowCloneTrait"): Indicates to the magic [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") method of a class that it is **legal** for that method to make a **shallow** field-for-field copy of instances of that class.
5. The trait [`FlorianWolters\Component\Core\DeepCloneTrait`](src/main/php/DeepCloneTrait.php "FlorianWolters\Component\Core\DeepCloneTrait"): Indicates to the magic [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") method of a class that it is **legal** for that method to make a **deep** field-for-field copy of instances of that class.
6. The static class [`FlorianWolters\Component\Core\CloneUtils`](src/main/php/CloneUtils.php "FlorianWolters\Component\Core\CloneUtils"): Offers operations to clone objects.

Features
--------

[](#features)

- Disallows cloning via the magic method [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") by using the trait [`CloneNotSupportedTrait`](src/main/php/CloneNotSupportedTrait.php "FlorianWolters\Component\Core\CloneNotSupportedTrait"). When trying to copy an object via the `clone` keyword, a [`CloneNotSupportedException`](src/main/php/CloneNotSupportedException.php "FlorianWolters\Component\Core\CloneNotSupportedException") is thrown.
- Allows (type safe) cloning via the magic method [`__clone`](https://php.net/language.oop5.cloning "PHP: Object Cloning") by implementing the interface [`CloneableInterface`](src/main/php/CloneableInterface.php "FlorianWolters\Component\Core\CloneableInterface") and using one of the two traits [`ShallowCloneTrait`](src/main/php/ShallowCloneTrait.php "FlorianWolters\Component\Core\ShallowCloneTrait") to make a **shallow** or [`DeepCloneTrait`](src/main/php/DeepCloneTrait.php "FlorianWolters\Component\Core\DeepCloneTrait") to make a **deep** copy of an instance of the class.
- Allows creating **deep** copies of any object via the method `copyDeep` of the class [`CloneUtils`](src/main/php/CloneUtils.php "FlorianWolters\Component\Core\CloneUtils").
- 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-cloneable "florianwolters/component-core-cloneable - Packagist") for the package on [Packagist](https://packagist.org "Packagist").
- Provides a complete Application Programming Interface (API) documentation generated with the documentation generator [phpDocumentor](http://phpdoc.org "phpDocumentor"). Click [here](http://blog.florianwolters.de/PHP-Component-Core-Cloneable "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")
- [PDepend](http://pdepend.org "PHP Depend - Software Metrics for PHP")
- [phpDocumentor](http://phpdoc.org "phpDocumentor")
- [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker "SensioLabs Security Checker")
- [php-coveralls](https://github.com/satooshi/php-coveralls "satooshi/php-coveralls · GitHub")

Usage
-----

[](#usage)

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

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

[](#installation)

**FlorianWolters\\Component\\Core\\Cloneable** 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

```

As A Dependency On Your Component
---------------------------------

[](#as-a-dependency-on-your-component)

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

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

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

[](#contributing)

See [`CONTRIBUTING.md`](CONTRIBUTING.md).

Credits
-------

[](#credits)

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

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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

4808d ago

### 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 (42 commits)")

---

Tags

clonecreationcloning

### Embed Badge

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

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

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M441](/packages/symfony-var-exporter)[verbb/cloner

Easily clone sections, entry types, groups and more.

25178.7k](/packages/verbb-cloner)[florianwolters/component-util-singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

13175.8k5](/packages/florianwolters-component-util-singleton)

PHPackages © 2026

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