I'm using PHP-Parser to evaluate the conditions used to traverse the if statement. I just want to know what the conditions used during the traversing of the code. For example:
test
<?php
$val = true;
if ($val == true){
$result = true;
} else {
$result = false;
}
I already found the AST of the test code, which is as following
AST
array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: val ) expr: Expr_ConstFetch( name: Name( parts: array( 0: true ) ) ) ) ) 1: Stmt_If( cond: Expr_BinaryOp_Equal( left: Expr_Variable( name: val ) right: Expr_ConstFetch( name: Name( parts: array( 0: true ) ) ) ) stmts: array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: result ) expr: Expr_ConstFetch( name: Name( parts: array( 0: true ) ) ) ) ) ) elseifs: array( ) else: Stmt_Else( stmts: array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: result ) expr: Expr_ConstFetch( name: Name( parts: array( 0: false ) ) ) ) ) ) ) ) )
What I'm trying to get is what the condition used in the test code during the traverse, which is expect to be something like this:
Expected result
Conditions: (operator: Equal true:bool,true:bool,)
// OR
Condition: (operator: NOT (operator: Equal true:bool,true:bool,),)
So I'm just wondering how to get the conditions that passing during the traverse.