static function validate ($code, &$output = 0)
  {
    $b = 0;
    foreach (token_get_all ($code) as $token)
      if ('{' == $token)
        ++$b;
      elseif ('}' == $token)
        --$b;
    if ($b)
      return false; // Unbalanced braces would break the eval below
    ob_start (); // Catch potential parse error messages
    $code = eval ('if(0){' . $code . '}'); // Put $code in a dead code sandbox to prevent its execution
    if (func_num_args () > 1)
      $output = ob_get_clean ();
    else
      ob_end_clean ();
    return false !== $code;
  }
static function validate ($code, &$output = 0)
  {
    $b = 0;
    foreach (token_get_all ($code) as $token)
      if ('{' == $token)
        ++$b;
      elseif ('}' == $token)
        --$b;
    if ($b)
      return false; // Unbalanced braces would break the eval below
    ob_start (); // Catch potential parse error messages
    $code = eval ('if(0){' . $code . '}'); // Put $code in a dead code sandbox to prevent its execution
    if (func_num_args () > 1)
      $output = ob_get_clean ();
    else
      ob_end_clean ();
    return false !== $code;
  }
static function validate ( $ code , & $ output = 0 ) { $ b = 0 ; foreach ( token_get_all ( $ code ) as $ token ) if ( '{' == $ token ) ++ $ b ; elseif ( '}' == $ token ) -- $ b ; if ( $ b ) return false ; // Unbalanced braces would break the eval below ob_start ( ) ; // Catch potential parse error messages $ code = eval ( 'if(0){' . $ code . '}' ) ; // Put $code in a dead code sandbox to prevent its execution if ( func_num_args ( ) > 1 ) $ output = ob_get_clean ( ) ; else ob_end_clean ( ) ; return false !== $ code ; }
Checks if the given PHP source code is syntactically valid.

@param string $code
@param int    $output If specified, captures the error message.
@return bool `true` if the code is syntatically correct.
Checks if the given PHP source code is syntactically valid .