title: How does doctrine entity manager flush() method works?
body: <p>In the <a href="http://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started.html#starting-with-the-product" rel="noreferrer">Doctrine documentation</a> there is this code:</p>
  
  <pre><code>&lt;?php
  // update_product.php &lt;id&gt; &lt;new-name&gt;
  require_once "bootstrap.php";
  
  $id = $argv[1];
  $newName = $argv[2];
  
  $product = $entityManager-&gt;find('Product', $id);
  
  if ($product === null) {
      echo "Product $id does not exist.\n";
      exit(1);
  }
  
  $product-&gt;setName($newName);
  
  $entityManager-&gt;flush();
  </code></pre>
  
  <p>What I don't understand is the last part, where, after setting the product name with <code>$product-&gt;setName()</code>, the <code>$entityManager-&gt;flush()</code> method is called:</p>
  
  <pre><code>$product-&gt;setName($newName);
  $entityManager-&gt;flush();
  </code></pre>
  
  <p>It seems to me that there is no connection between the <code>$product</code> variable and the <code>$entityManager</code> variable, except for the fact that <code>$product</code> should contain the response from the <code>$entityManager-&gt;find()</code> method.</p>
  
  <p>How is it possible that <code>$entityManager-&gt;flush()</code> can read values set by <code>$product-&gt;setName()</code>?</p>