Итак, я хочу сохранить значение ArrayCollection, удалить его, а затем повторно использовать в другом объекте. Но кажется, что значение передается по ссылке, поэтому, когда оно не установлено, сохраненное значение также не устанавливается.
$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;
}
Итак, есть ли способ сохранить значение arrayCollection, прежде чем я его удалю?
Кстати, я на Symfony 3.4.
$children = clone $role->getChildren();
должен работать. (дети должны быть клонируемыми объектами) - person j-guyon   schedule 12.03.2018