1. Go to this page and download the library: Download symfony/deepclone library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$payload = deepclone_to_array($graph);
$json = json_encode($payload); // safe — no objects in the array
// ... send over the wire, store in a DB, etc.
$clone = deepclone_from_array(json_decode($json, true));
// Flat bare-name array — ideal for hydrating from a flat row
// (e.g. a PDO result).
$user = deepclone_hydrate(User::class, [
'id' => 42,
'name' => 'Alice',
'email' => '[email protected]',
]);
// Mangled keys for parent-declared private properties — same format as
// (array) $obj cast produces.
$user = deepclone_hydrate(User::class, [
'name' => 'Alice',
"\0AbstractEntity\0createdAt" => new \DateTimeImmutable(),
]);
// Hydrate an existing object
deepclone_hydrate($existingUser, ['name' => 'Bob']);
function deepclone_to_array(mixed $value, ?array $allowed_classes = null, bool $allow_named_closures = false): array;
function deepclone_from_array(array $data, ?array $allowed_classes = null, bool $allow_named_closures = false): mixed;
function deepclone_hydrate(object|string $object_or_class, array $vars = [], int $flags = 0): object;
$clone = deepclone_from_array($payload);
// closure-bearing nodes are uninitialized ghosts; reading any property
// of such a node hydrates that node only.
$user = deepclone_hydrate(User::class, [
'id' => 42, // bare — public or own-private
'name' => 'Alice',
"\0*\0createdAt" => new \DateTimeImmutable(), // protected
"\0AbstractEntity\0metadata" => [...], // parent-private
]);