title: Test if variable contains circular references
body: <p><strong>How do you test a variable for circular references?</strong></p>
  
  <p>I am using PHP's <code>var_export()</code> function with the return string argument set to <code>true</code>.</p>
  
  <p>I found that <code>Warning: var_export does not handle circular references</code> and was wondering if anyone knew of a way to test if a variable contains a circular reference so that I may use it before trying to use <code>var_export</code> on it.</p>
  
  <p>I know that <code>var_export</code> outputs PHP eval-able text that can be used to recreate the array and even though I am not using it for that I still want to use this function when it is available because the output format meets my needs. <code>var_dump</code> is not an option because it doesn't accept an argument to return a string instead. I am aware that I could buffer the output of <code>var_dump</code> which handles circular references gracefully and save the buffer contents to a variable but I really just want to know if someone knows of a way to test for such references in a variable.</p>
  
  <p>If you want to create a quick circular reference do this:</p>
  
  <pre><code>$r = array();
  $r[] = &amp;$r;
  var_export($r, true);
  </code></pre>