Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConstExprEvaluator.php

function ConstExprEvaluator::evaluateSilently

Silently evaluates a constant expression into a PHP value.

Thrown Errors, warnings or notices will be converted into a ConstExprEvaluationException. The original source of the exception is available through getPrevious().

If some part of the expression cannot be evaluated, the fallback evaluator passed to the constructor will be invoked. By default, if no fallback is provided, an exception of type ConstExprEvaluationException is thrown.

See class doc comment for caveats and limitations.

Parameters

Expr $expr Constant expression to evaluate:

Return value

mixed Result of evaluation

Throws

ConstExprEvaluationException if the expression cannot be evaluated or an error occurred

File

vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php, line 66

Class

ConstExprEvaluator
Evaluates constant expressions.

Namespace

PhpParser

Code

public function evaluateSilently(Expr $expr) {
    set_error_handler(function ($num, $str, $file, $line) {
        throw new \ErrorException($str, 0, $num, $file, $line);
    });
    try {
        return $this->evaluate($expr);
    } catch (\Throwable $e) {
        if (!$e instanceof ConstExprEvaluationException) {
            $e = new ConstExprEvaluationException("An error occurred during constant expression evaluation", 0, $e);
        }
        throw $e;
    } finally {
        restore_error_handler();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal