Skip to content

Instantly share code, notes, and snippets.

@BlackScorp
Created May 1, 2022 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlackScorp/de8e3d63f54fae912ce6fad4cf672116 to your computer and use it in GitHub Desktop.
Save BlackScorp/de8e3d63f54fae912ce6fad4cf672116 to your computer and use it in GitHub Desktop.
testing deep clones
<?php
class SubSubChild {
public function __construct(private string $value)
{
}
}
class OtherObject{
public function __construct(private SubSubChild $subSubChild)
{
}
}
class SomeObject
{
private string $property;
public function __construct(private OtherObject $child)
{
}
public function getProperty(): string
{
return $this->property;
}
public function setProperty(string $property): SomeObject
{
$clone = clone $this;
$clone->property = $property;
return $clone;
}
}
$object = new SomeObject(new OtherObject(new SubSubChild('test')));
$object2 = $object->setProperty('test');
$object3 = $object2->setProperty('test2');
var_dump($object2);
var_dump($object3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment