title: How can I get data from object with foreach loop in Symfony?
body: <pre><code>$EntityName = 'App\\Entity\\' . ucwords($slug);
  $item = new $EntityName();    
  $item= $this-&gt;getDoctrine()-&gt;getRepository($EntityName)-&gt;find($id);
      $form = $this-&gt;createFormBuilder($item)
  </code></pre>
  
  <p>content of <code>$item</code>:</p>
  
  <pre><code>object(App\Entity\Members)#4788 (6) {
    ["id":"App\Entity\Members":private]=&gt;
    int(9)
    ["username":"App\Entity\Members":private]=&gt;
    string(13) "123"
    ["plainPassword":"App\Entity\Members":private]=&gt;
    NULL
    ["password":"App\Entity\Members":private]=&gt;
    string(0) ""
    ["email":"App\Entity\Members":private]=&gt;
    string(7) "1@12.sw"
    ["isActive":"App\Entity\Members":private]=&gt;
    bool(true)
  }
  </code></pre>
  
  <p>I try to get the fields from $item.</p>
  
  <p>As an output I want to have</p>
  
  <pre><code>id
  username
  password
  email
  isActive
  </code></pre>
  
  <p>to create the fields.</p>
  
  <p>My approach is:</p>
  
  <pre><code>foreach($item as $field){
     echo $field;
  }
  </code></pre>
  
  <p>But I do not get any output</p>