Eloquent\Phony\Reflection\FeatureDetector::checkStatement PHP Method

checkStatement() public method

Check that the supplied syntax is valid.
public checkStatement ( string $source, boolean $useClosure = true ) : boolean
$source string The source to check.
$useClosure boolean True to wrap the supplied source code in a closure.
return boolean True if the syntax is valid.
    public function checkStatement($source, $useClosure = true)
    {
        $reporting = error_reporting(E_ERROR | E_COMPILE_ERROR);
        $error = null;
        if ($useClosure) {
            try {
                $result = eval(sprintf('function(){%s;};return true;', $source));
            } catch (ParseError $e) {
                $result = false;
                // @codeCoverageIgnoreStart
            } catch (ParseException $e) {
                $result = false;
            } catch (Throwable $error) {
            } catch (Exception $error) {
            }
            // @codeCoverageIgnoreEnd
        } else {
            try {
                $result = eval(sprintf('%s;return true;', $source));
                // @codeCoverageIgnoreStart
            } catch (ParseError $e) {
                $result = false;
            } catch (ParseException $e) {
                $result = false;
            } catch (Throwable $error) {
            } catch (Exception $error) {
            }
            // @codeCoverageIgnoreEnd
        }
        error_reporting($reporting);
        if ($error) {
            throw $error;
        }
        return true === $result;
    }