Linux unitednationsplay.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
nginx/1.20.1
Server IP : 188.130.139.92 & Your IP : 3.133.142.101
Domains :
Cant Read [ /etc/named.conf ]
User : web
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
home /
www /
3 /
nikic /
php-parser /
doc /
component /
Delete
Unzip
Name
Size
Permission
Date
Action
AST_builders.markdown
5.24
KB
-rw-r--r--
2018-10-10 09:00
Constant_expression_evaluation.markdown
3.31
KB
-rw-r--r--
2018-10-10 09:00
Error_handling.markdown
2.69
KB
-rw-r--r--
2018-10-10 09:00
FAQ.markdown
2.06
KB
-rw-r--r--
2018-10-10 09:00
JSON_representation.markdown
3.4
KB
-rw-r--r--
2018-10-10 09:00
Lexer.markdown
7.55
KB
-rw-r--r--
2018-10-10 09:00
Name_resolution.markdown
4.04
KB
-rw-r--r--
2018-10-10 09:00
Performance.markdown
3.25
KB
-rw-r--r--
2018-10-10 09:00
Pretty_printing.markdown
4.1
KB
-rw-r--r--
2018-10-10 09:00
Walking_the_AST.markdown
11.3
KB
-rw-r--r--
2018-10-10 09:00
Save
Rename
Constant expression evaluation ============================== Initializers for constants, properties, parameters, etc. have limited support for expressions. For example: ```php <?php class Test { const SECONDS_IN_HOUR = 60 * 60; const SECONDS_IN_DAY = 24 * self::SECONDS_IN_HOUR; } ``` PHP-Parser supports evaluation of such constant expressions through the `ConstExprEvaluator` class: ```php <?php use PhpParser\{ConstExprEvaluator, ConstExprEvaluationException}; $evalutator = new ConstExprEvaluator(); try { $value = $evalutator->evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Either the expression contains unsupported expression types, // or an error occurred during evaluation } ``` Error handling -------------- The constant evaluator provides two methods, `evaluateDirectly()` and `evaluateSilently()`, which differ in error behavior. `evaluateDirectly()` will evaluate the expression as PHP would, including any generated warnings or Errors. `evaluateSilently()` will instead convert warnings and Errors into a `ConstExprEvaluationException`. For example: ```php <?php use PhpParser\{ConstExprEvaluator, ConstExprEvaluationException}; use PhpParser\Node\{Expr, Scalar}; $evaluator = new ConstExprEvaluator(); // 10 / 0 $expr = new Expr\BinaryOp\Div(new Scalar\LNumber(10), new Scalar\LNumber(0)); var_dump($evaluator->evaluateDirectly($expr)); // float(INF) // Warning: Division by zero try { $evaluator->evaluateSilently($expr); } catch (ConstExprEvaluationException $e) { var_dump($e->getPrevious()->getMessage()); // Division by zero } ``` For the purposes of static analysis, you will likely want to use `evaluateSilently()` and leave erroring expressions unevaluated. Unsupported expressions and evaluator fallback ---------------------------------------------- The constant expression evaluator supports all expression types that are permitted in constant expressions, apart from the following: * `Scalar\MagicConst\*` * `Expr\ConstFetch` (only null/false/true are handled) * `Expr\ClassConstFetch` Handling these expression types requires non-local information, such as which global constants are defined. By default, the evaluator will throw a `ConstExprEvaluationException` when it encounters an unsupported expression type. It is possible to override this behavior and support resolution for these expression types by specifying an evaluation fallback function: ```php <?php use PhpParser\{ConstExprEvaluator, ConstExprEvaluationException}; use PhpParser\Node\Expr; $evalutator = new ConstExprEvaluator(function(Expr $expr) { if ($expr instanceof Expr\ConstFetch) { return fetchConstantSomehow($expr); } if ($expr instanceof Expr\ClassConstFetch) { return fetchClassConstantSomehow($expr); } // etc. throw new ConstExprEvaluationException( "Expression of type {$expr->getType()} cannot be evaluated"); }); try { $evalutator->evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Handle exception } ``` Implementers are advised to ensure that evaluation of indirect constant references cannot lead to infinite recursion. For example, the following code could lead to infinite recursion if constant lookup is implemented naively. ```php <?php class Test { const A = self::B; const B = self::A; } ```