title: How to trim object properties in PHP?
body: <p>I have an object <code>$obj</code> as</p>
  
  <pre><code>$obj-&gt;{' Property1'} = " value1";
  $obj-&gt;{'Property2 '} = "value2 ";
  </code></pre>
  
  <p>I want to get this object <code>$obj</code> as</p>
  
  <pre><code>$obj-&gt;{'Property1'} = "value1";
  $obj-&gt;{'Property2'} = "value2";
  </code></pre>
  
  <p>I am able to trim all the values using</p>
  
  <pre><code>foreach($obj as $prop =&gt; &amp;$val)
  {
       $val = trim($val);
  }
  </code></pre>
  
  <p>but doing this (below) causing an error</p>
  
  <pre><code>foreach($obj as &amp;$prop =&gt; &amp;$val)
  {
       $prop = trim($prop);
       $val = trim($val);
  }
  </code></pre>
  
  <p>Please tell a solution.
  Thanks in advance.</p>