So I want to store the ArrayCollection value, delete it and then reuse it in another entity. But it seems that the value is passed by reference so when its unset, the stored value is also unset.
$children = $role->getChildren();
var_dump(count($children)); // int(1)
$role->removeAllChildren();
var_dump(count($children)); // int(0)
/** **/
/**
* @return Role
*/
public function removeAllChildren()
{
foreach ($this->children as $child) {
$this->removeChild($child);
}
return $this;
}
/**
* @param Role $child
*
* @return Role
*/
public function removeChild(Role $child)
{
if ($this->hasChild($child)) {
$this->children->removeElement($child);
// this calls unset($this->elements[$key]);
}
return $this;
}
So is there a way to store the arrayCollection value before I remove it ?
I'm on Symfony 3.4 by the way.