Enhance ConstExprEvaluator by evaluating new type of expressions or enhancing some (hopefully)#1107
Enhance ConstExprEvaluator by evaluating new type of expressions or enhancing some (hopefully)#1107odain-cbd wants to merge 5 commits intonikic:masterfrom
Conversation
…om/Combodo/iTop Added: - Variable - Isset - ClassConstFetch - Cast - StaticPropertyFetch - FuncCall - StaticCall - NullsafePropertyFetch - PropertyFetch - NullsafeMethodCall - MethodCall Enhanced: - ConstFetch - Coalesce
nikic
left a comment
There was a problem hiding this comment.
The purpose of ConstExprEvaluator is to evaluate "constant expressions", such as the right hand side of const X = .... These constant expressions only support a limited set of operations.
What you seem to be implementing here seems to be a lot broader: It's trying to evaluate all expressions, and accessing global state (like global variables) for that purpose. While this is may be useful for some use cases, it does not fit the purpose of ConstExprEvaluator and this behavior would be highly undesirable in most circumstances (static analyzers do not typically run in the same execution context as the code they're analyzing, so this just ends up accessing global state from the analyzer).
|
Thanks for the feedback. Keeping the purpose of ConstExprEvaluator, I left only below enhancements in this class: All non-constant evaluations have been moved in ExprEvaluator class. with associated tests as well. |
|
Hello @nikic , could this be reconsidered please? Thanks :) |
…on's one is used)
For iTop project we had to enhance ConstExprEvaluator to parse/evaluate few of our PHP files. Below are listed the added/enhanced Expression usecases.
(https://github.com/Combodo/iTop/tree/feature/4789-nikicfork)
Added:
- Variable
- Isset
- ClassConstFetch
- Cast
- StaticPropertyFetch
- FuncCall
- StaticCall
- NullsafePropertyFetch
- PropertyFetch
- NullsafeMethodCall
- MethodCall
Enhanced:
- ConstFetch
- Coalesce