How can I remove a private property from array?

$array = $this->em->getRepository($entity)->filter($id);

With doctrine I am creating an array:

array:24 [▼
  0 => Members^ {#543 ▼
    -id: 1
    -username: "lio"
    -email: "[email protected]"
    -isActive: true
    -name: "Lio"
    -projects: PersistentCollection^ {#590 ▶}
    -pages: PersistentCollection^ {#615 ▶}
  }
  1 => Members^ {#135029 ▶}
  2 => Members^ {#125937 ▶}
  3 => Members^ {#1807 ▶}
  4 => Members^ {#135075 ▶}
  5 => Members^ {#135086 ▶}

From this array I try to remove the object projects:

 foreach ($array as $value) {
      dump($value->projects);
    }

I get the error message that the object is private.

I found this post, but there it is written, that I need to write a function inside the class.

Removing private properties of object

My question is, is it possible to remove it outside the class? Because when I remove it inside the class it is always removed and I want to remove it only in a specific case.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *