Download the PHP package symfony/deepclone without Composer

On this page you can find all versions of the php package symfony/deepclone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package deepclone

deepclone

CI

A PHP extension that deep-clones any serializable PHP value while preserving copy-on-write for strings and arrays — resulting in lower memory usage and better performance than unserialize(serialize()).

It works by converting the value graph to a pure-array representation (only scalars and nested arrays, no objects) and back. This array form is the wire format used by Symfony's VarExporter\DeepCloner, making the extension a transparent drop-in accelerator.

Use cases

Repeated cloning of a prototype. Calling unserialize(serialize()) in a loop allocates fresh copies of every string and array, blowing up memory. This extension preserves PHP's copy-on-write: strings and scalar arrays are shared between clones until they are actually modified.

OPcache-friendly cache format. The pure-array payload is suitable for var_export(). When cached in a .php file, OPcache maps it into shared memory — making the "unserialize" step essentially free:

Serialization to any format. The array form can be passed to json_encode(), MessagePack, igbinary, APCu, or any transport that handles plain PHP arrays — without losing object identity, cycles, references, or private property state.

Fast object instantiation and hydration. Create objects and set their properties — including private, protected, and readonly ones — without calling their constructor, faster than Reflection:

API

$allowed_classes restricts which classes may be serialized or deserialized (null = allow all, [] = allow none). Case-insensitive, matching unserialize()'s allowed_classes option.

$allow_named_closures controls the by-name encoding of closures over named callables (first-class callables such as strlen(...), $obj->method(...) or Cls::method(...), and Closure::fromCallable()). It defaults to false, and both ends must enable it: deepclone_to_array() refuses to encode such a closure unless it is set, and deepclone_from_array() refuses to resolve a by-name closure payload unless it is set. The reason is that a by-name payload can mint a Closure over any function or method of that name, including internal functions like system(), so it should only travel between ends that trust each other. Closures declared in constant expressions (anonymous static closures and first-class callables over a method of their own declaring class, e.g. #[When(self::isStrict(...))]) are not affected: they serialize as a reference to their declaration site, resolvable only to what the named class itself declares, and round-trip without this option.

Lazy hydration of closure-bearing nodes (PHP 8.4+)

deepclone_from_array() creates the object nodes that are expensive to hydrate as native lazy ghosts: nodes whose payload slots or replayed __unserialize state carry a named-closure or (PHP 8.5) const-expr-closure marker, since resolving those (fake-closure creation, attribute-args re-evaluation) is where hydration time actually goes. Every object identity exists when the call returns (back-references, shared & references and === behave exactly as for eager nodes), but a ghost's property hydration, closure resolution included, is deferred until the engine first touches it.

All other nodes hydrate eagerly: nodes without closure markers (plain value slots are cheaper to hydrate than to ghost, since copy-on-write makes them refcount bumps), internal classes (and classes inheriting one, stdClass descendants excepted), and stdClass itself and other classes without declared properties. A graph without closure markers is hydrated fully eagerly and carries zero lazy-mode overhead, and on PHP older than 8.4 (no native lazy objects) everything hydrates eagerly. Mixing lazy and eager nodes in one graph is the normal mode of operation.

Closure-bearing nodes that replay __wakeup/__unserialize are deferred too: their hook runs at the end of their own initialization instead of in the global, children-first replay sequence (each entry is still validated inside the call; only the hook calls move). State-replaying nodes without closure markers keep their eager, ordered replay.

Semantics of deferred nodes (the usual native lazy-object rules):

Cost model (20k-node graphs, PHP 8.4 release build): compared with resolving every closure inside the call, deferral makes closure-rich graphs 4-6x faster to create and partially consume, 2-3x smaller while untouched (lazy shells plus the slot index weigh less than materialized closures), and about 2x faster to tear down when dropped untouched. A fully traversed graph pays a comparable total, at first touch instead of inside the call. Graphs without closure markers take the eager path.

deepclone_hydrate() accepts either an object to hydrate in place or a class name to instantiate without calling its constructor. By default, PHP & references in $vars are dropped on write; pass DEEPCLONE_HYDRATE_PRESERVE_REFS to keep them.

$vars is a flat array keyed by property name — the exact shape (array) $obj produces:

key shape target
"propName" public, protected (any declaring class), or private declared on the object's own class
"\0*\0propName" protected (the declaring class is resolved via the object)
"\0ClassName\0propName" private declared on ClassName — must be the object's own class or a parent

Each key triggers one properties_info hash lookup followed by a direct slot write.

Bare names are enough for every public, protected, or most-derived-private property. Parent-declared private properties need the explicit "\0ClassName\0prop" mangled form (the engine keys them that way in the child's properties_info).

$flags selects the write semantics for declared-property assignments:

Flag Semantics
0 (default) ReflectionProperty::setRawValue — bypass set hooks, type-check, respect readonly
DEEPCLONE_HYDRATE_CALL_HOOKS ReflectionProperty::setValue — invoke set hooks
DEEPCLONE_HYDRATE_NO_LAZY_INIT ReflectionProperty::setRawValueWithoutLazyInitialization — skip the lazy initializer; realize the object when the last lazy property is set
DEEPCLONE_HYDRATE_PRESERVE_REFS preserve PHP & references from $vars onto the target property slots; by default, references are dropped (dereferenced) on write

DEEPCLONE_HYDRATE_CALL_HOOKS and DEEPCLONE_HYDRATE_NO_LAZY_INIT are mutually exclusive; PRESERVE_REFS composes with either. deepclone_from_array() always uses the default setRawValue semantics, mirroring unserialize().

PRESERVE_REFS is off by default because preserving references requires a per-call probe of the input array, which costs more than the typical DTO hydration saves by using the ext over Reflection. Pass the flag when you actually need a property slot to remain aliased to a caller-side variable or to another property (e.g. when rehydrating a graph previously exported with deepclone_to_array() that contained & references).

Forgiving payload handling

deepclone_hydrate() applies three coercions before writing each declared property, so common rehydration patterns don't trip on strict-type errors. They run under every mode unless noted:

SPL classes that hold internal state (ArrayObject, ArrayIterator, SplObjectStorage, …) have shipped __serialize / __unserialize since PHP 7.4. To populate them, instantiate with deepclone_hydrate() and call __unserialize() with the array shape the class documents — or just use deepclone_from_array(), which routes through __unserialize natively.

What it preserves

Error handling

Exception Thrown by When
DeepClone\NotInstantiableException deepclone_to_array, deepclone_hydrate Resource, anonymous class, Reflection*, internal class without serialization support
DeepClone\ClassNotFoundException deepclone_from_array, deepclone_hydrate Payload/class name references a class that doesn't exist
ValueError all three Malformed input, or class not in $allowed_classes

Both exception classes extend \InvalidArgumentException.

Requirements

Installation

With PIE (recommended)

Then enable in php.ini:

Manual build

With Symfony

symfony/var-exporter and symfony/polyfill-deepclone provide the same deepclone_to_array(), deepclone_from_array(), and deepclone_hydrate() functions in pure PHP. When this extension is loaded it replaces the polyfill transparently — no code change needed.

Symfony's Hydrator::hydrate() and Instantiator::instantiate() delegate directly to deepclone_hydrate(), making them thin one-liner wrappers.

License

Released under the MIT license.


All versions of deepclone with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package symfony/deepclone contains the following files

Loading the files please wait ...