title: Why use clone keyword here
body: <p>I am watching a tutorial of SPL and here is the code that confuses me</p>
  
  <pre><code>&lt;?php
  
  $directory = new DirectoryIterator('common/images');
  
  foreach ($directory as $file)
  {
      if($file-&gt;isFile())
          $files[] = clone $file;
  }
  
  echo $files[1]-&gt;getFileName();
  </code></pre>
  
  <p>If i don't use <code>clone</code> keyword in the foreach loop, I am not able to see the filename. Why is that so when i am pushing the whole object inside the <code>$files</code> array.</p>
  
  <p>Thanks</p>
  
  <p>Updated Part</p>
  
  <p>While the above code i have to used the <code>clone</code> keyword. Based on the answer below that we are using <code>clone</code> to create a copy of object not reference. That doesn't seems to be a valid reason in this case. Consider the following example which does not need clone keyword and is working as expected</p>
  
  <pre><code>&lt;?php
  
  $filesystem = new FilesystemIterator('common/images');
  foreach ($filesystem as $file)
  {
      $files[] = $file;
  }
  
  echo $files[0]-&gt;getFileName();
  </code></pre>