3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Chain { private $values = []; public function __construct($x) { $this->values[] = $x; } public function __invoke($x) { if ($x instanceof Closure) { return array_reduce($this->values, $x); } $this->values[] = $x; return $this; } } var_dump((new Chain(1))(2)(3)(function ($x, $y) { return $x + $y; }));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SgZjT
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'var_dump'
          1        NEW                                              $0      'Chain'
          2        SEND_VAL_EX                                              1
          3        DO_FCALL                                      0          
          4        INIT_DYNAMIC_CALL                                        $0
          5        SEND_VAL_EX                                              2
          6        DO_FCALL                                      0  $2      
          7        INIT_DYNAMIC_CALL                                        $2
          8        SEND_VAL_EX                                              3
          9        DO_FCALL                                      0  $3      
         10        INIT_DYNAMIC_CALL                                        $3
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSgZjT%3A16%240'
         12        SEND_VAL_EX                                              ~4
         13        DO_FCALL                                      0  $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FSgZjT%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SgZjT
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSgZjT%3A16%240

Class Chain:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SgZjT
function name:  __construct
number of ops:  5
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        FETCH_OBJ_W                                      $1      'values'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
    6     4      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SgZjT
function name:  __invoke
number of ops:  15
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INSTANCEOF                                               !0, 'Closure'
          2      > JMPZ                                                     ~1, ->9
    9     3    >   INIT_FCALL                                               'array_reduce'
          4        FETCH_OBJ_R                                      ~2      'values'
          5        SEND_VAL                                                 ~2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
   11     9    >   FETCH_OBJ_W                                      $4      'values'
         10        ASSIGN_DIM                                               $4
         11        OP_DATA                                                  !0
   12    12        FETCH_THIS                                       ~6      
         13      > RETURN                                                   ~6
   13    14*     > RETURN                                                   null

End of function __invoke

End of class Chain.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.2 ms | 1400 KiB | 17 Q