3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StatefulAdderFactory { private $x = 1; function getAdder() { return new class($this->x) { function add($y) { $this->x += $y; return $this->x; } }; } } $saf = new StatefulAdderFactory(); $adder = $saf->getAdder(); var_dump($adder->add(42)); var_dump($adder->add(21));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N4nc9
function name:  (null)
number of ops:  19
compiled vars:  !0 = $saf, !1 = $adder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $2      'StatefulAdderFactory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   17     3        INIT_METHOD_CALL                                         !0, 'getAdder'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
   19     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'add'
          8        SEND_VAL_EX                                              42
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
   20    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !1, 'add'
         14        SEND_VAL_EX                                              21
         15        DO_FCALL                                      0  $9      
         16        SEND_VAR                                                 $9
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class class@anonymous:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N4nc9
function name:  add
number of ops:  6
compiled vars:  !0 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ_OP                                 1          'x'
          2        OP_DATA                                                  !0
   10     3        FETCH_OBJ_R                                      ~2      'x'
          4      > RETURN                                                   ~2
   11     5*     > RETURN                                                   null

End of function add

End of class class@anonymous.

Class StatefulAdderFactory:
Function getadder:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N4nc9
function name:  getAdder
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_ANON_CLASS                               <array> 
          1        NEW                                              $1      $0
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $2      'x'
          4        SEND_FUNC_ARG                                            $2
          5        DO_FCALL                                      0          
          6      > RETURN                                                   $1
   13     7*     > RETURN                                                   null

End of function getadder

End of class StatefulAdderFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.61 ms | 1396 KiB | 15 Q