Class PhpParser\ConstExprEvaluator

Evaluates constant expressions.

This evaluator is able to evaluate all constant expressions (as defined by PHP), which can be evaluated without further context. If a subexpression is not of this type, a user-provided fallback evaluator is invoked. To support all constant expressions that are also supported by PHP (and not already handled by this class), the fallback evaluator must be able to handle the following node types:

  • All Scalar\MagicConst* nodes.
  • Expr\ConstFetch nodes. Only null/false/true are already handled by this class.
  • Expr\ClassConstFetch nodes.

The fallback evaluator should throw ConstExprEvaluationException for nodes it cannot evaluate.

The evaluation is dependent on runtime configuration in two respects: Firstly, floating point to string conversions are affected by the precision ini setting. Secondly, they are also affected by the LC_NUMERIC locale.

Methods