title: PHP - Check PHP Code for Syntax Errors without running the code
body: <p>I know that by using <code>eval($code_to_check);</code> we can check if this value equals <code>FALSE</code> and if so, we can stop execution of the script.  However, the problem I'm facing is that I am unable to define a function, because it gets called twice...  it gets processed with the eval() check to be sure there are no syntax errors and than processes the function again, but shows an error that states that it can NOT REDECLARE this function, as it is already being declared in the eval'd function.  How can I make it so that we don't declare things in the EVAL'd function, or perhaps, we can undeclare everything that was declared in the eval() function before we actually do call it...</p>
  
  <p>Anyways, here is what I'm working with so far...  Could use some help, cause I am getting a "CAN NOT REDECLARE FUNCTION" when $content (which is php code) has a function within it.</p>
  
  <pre><code>// PHP Syntax errors?
  if (!@eval('return true;' . $content))
  {
      // Error found in PHP somewhere.  Call error function and return out of here!
      call_user_func_array($code_error['function'], $code_error['params']);
      return;
  }
  else
  {
      ob_start();
  
      eval($content);
      $code = ob_get_contents();
      ob_end_clean();
  }
  </code></pre>
  
  <p>Can anyone please help me here?  Thanks guys, you are all so very helpful here!  You all deserve a GOLD MEDAL, but I believe the Olympics are now over and this isn't quite a sport yet...</p>
  
  <hr>
  
  <p>Ok, I am attempting my own answer here, and wondering if this will still catch errors and allow for functions to be created at the same time without calling these functions twice.  Is this a proper way of doing this??  Can anyone see any possible problems in this code?  I am echoing the $eval_code if no syntax errors detected... is this fine to do?</p>
  
  <pre><code>$eval_code = @eval($content);
  // PHP Syntax errors?
  if ($eval_code === FALSE)
  {
      call_user_func_array($code_error['function'], $code_error['params']);
      return;
  }
  else
  {
      ob_start();
      echo $eval_code;
      $code = ob_get_contents();
      ob_end_clean();
  }
  </code></pre>