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 |
public __construct(?callable $fallbackEvaluator = NULL) Create a constant expression evaluator. The provided fallback evaluator is invoked whenever a subexpression cannot be evaluated. See
|
public evaluateDirectly(PhpParser Directly evaluates a constant expression into a PHP value. May generate Error exceptions, warnings or notices. Use evaluateSilently() to convert these If some part of the expression cannot be evaluated, the fallback evaluator passed to the See class doc comment for caveats and limitations.
|
public evaluateSilently(PhpParser Silently evaluates a constant expression into a PHP value. Thrown Errors, warnings or notices will be converted into a ConstExprEvaluationException. If some part of the expression cannot be evaluated, the fallback evaluator passed to the See class doc comment for caveats and limitations.
|
Properties |
private $fallbackEvaluator = NULL |
Methods |
private evaluate(PhpParser |
private evaluateArray(PhpParser |
private evaluateBinaryOp(PhpParser |
private evaluateConstFetch(PhpParser |
private evaluateTernary(PhpParser |