-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg\Op\Expr; | ||
|
||
use PHPCfg\Func; | ||
use PHPCfg\Op\CallableOp; | ||
use PHPCfg\Op\Expr; | ||
|
||
class ArrowFunction extends Expr implements CallableOp | ||
{ | ||
public Func $func; | ||
|
||
public function __construct(Func $func, array $attributes = []) | ||
{ | ||
parent::__construct($attributes); | ||
$this->func = $func; | ||
} | ||
|
||
public function getVariableNames(): array | ||
{ | ||
return ['result']; | ||
} | ||
|
||
public function getFunc(): Func | ||
{ | ||
return $this->func; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
$b = 1; | ||
$fn = fn($a) => $b++ * $a; | ||
$fn(3); | ||
var_dump($b); | ||
----- | ||
Block#1 | ||
Expr_Assign | ||
var: Var#1<$b> | ||
expr: LITERAL(1) | ||
result: Var#2 | ||
Expr_ArrowFunction<'{anonymous}#1'> | ||
result: Var#3 | ||
Expr_Assign | ||
var: Var#4<$fn> | ||
expr: Var#3 | ||
result: Var#5 | ||
Expr_FuncCall | ||
name: Var#4<$fn> | ||
args[0]: LITERAL(3) | ||
result: Var#6 | ||
Expr_FuncCall | ||
name: LITERAL('var_dump') | ||
args[0]: Var#1<$b> | ||
result: Var#7 | ||
Terminal_Return | ||
|
||
Function '{anonymous}#1': mixed | ||
Block#1 | ||
Expr_Param | ||
declaredType: mixed | ||
name: LITERAL('a') | ||
result: Var#1<$a> | ||
Expr_BinaryOp_Plus | ||
left: Var#2<$b> | ||
right: LITERAL(1) | ||
result: Var#3 | ||
Expr_Assign | ||
var: Var#4<$b> | ||
expr: Var#3 | ||
result: Var#5 | ||
Expr_BinaryOp_Mul | ||
left: Var#4<$b> | ||
right: Var#1<$a> | ||
result: Var#6 | ||
Terminal_Return | ||
expr: Var#6 |