3v4l.org

run code in 500+ PHP versions simultaneously
<?php interface StrategyInterface { public function run(); } class Strategy implements StrategyInterface { protected ?string $value = null; private static $counter = 0; public function __construct(private Closure $closure) { echo "Strategy Counter: ", ++self::$counter, PHP_EOL; $this->value = (string)rand(1, 100); } public function run() { $this->closure->call($this); } public function __destruct() { echo "Strategy Counter: ", --self::$counter, PHP_EOL; } } $strategy1 = new Strategy(function () { var_dump($this->value); }); $strategy2 = new Strategy(function () { var_dump($this->value); }); $strategy3 = new Strategy(function () { var_dump($this->value); }); $strategy1->run(); $strategy1 = null; $strategy2->run(); unset($strategy2); $strategy3->run(); $strategy4 = new Strategy(function () { var_dump($this->value); });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  (null)
number of ops:  30
compiled vars:  !0 = $strategy1, !1 = $strategy2, !2 = $strategy3, !3 = $strategy4
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                                'strategy'
   30     1        NEW                                                  $4      'Strategy'
          2        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
   32     3        SEND_VAL_EX                                                  ~5
   30     4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $4
   34     6        NEW                                                  $8      'Strategy'
          7        DECLARE_LAMBDA_FUNCTION                              ~9      [1]
   36     8        SEND_VAL_EX                                                  ~9
   34     9        DO_FCALL                                          0          
         10        ASSIGN                                                       !1, $8
   38    11        NEW                                                  $12     'Strategy'
         12        DECLARE_LAMBDA_FUNCTION                              ~13     [2]
   40    13        SEND_VAL_EX                                                  ~13
   38    14        DO_FCALL                                          0          
         15        ASSIGN                                                       !2, $12
   43    16        INIT_METHOD_CALL                                             !0, 'run'
         17        DO_FCALL                                          0          
   44    18        ASSIGN                                                       !0, null
   45    19        INIT_METHOD_CALL                                             !1, 'run'
         20        DO_FCALL                                          0          
   46    21        UNSET_CV                                                     !1
   47    22        INIT_METHOD_CALL                                             !2, 'run'
         23        DO_FCALL                                          0          
   49    24        NEW                                                  $20     'Strategy'
         25        DECLARE_LAMBDA_FUNCTION                              ~21     [3]
   51    26        SEND_VAL_EX                                                  ~21
   49    27        DO_FCALL                                          0          
         28        ASSIGN                                                       !3, $20
   51    29      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  {closure:/in/smcDi:30}
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                                   'var_dump'
          1        FETCH_THIS                                           $0      
          2        FETCH_OBJ_R                                          ~1      $0, 'value'
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                                     
   32     5      > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  {closure:/in/smcDi:34}
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                                   'var_dump'
          1        FETCH_THIS                                           $0      
          2        FETCH_OBJ_R                                          ~1      $0, 'value'
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                                     
   36     5      > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  {closure:/in/smcDi:38}
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                                   'var_dump'
          1        FETCH_THIS                                           $0      
          2        FETCH_OBJ_R                                          ~1      $0, 'value'
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                                     
   40     5      > RETURN                                                       null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  {closure:/in/smcDi:49}
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                                   'var_dump'
          1        FETCH_THIS                                           $0      
          2        FETCH_OBJ_R                                          ~1      $0, 'value'
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                                     
   51     5      > RETURN                                                       null

End of Dynamic Function 3

Class StrategyInterface:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  run
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                       null

End of function run

End of class StrategyInterface.

Class Strategy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  __construct
number of ops:  15
compiled vars:  !0 = $closure
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'closure'
          2        OP_DATA                                                      !0
   15     3        ECHO                                                         'Strategy+Counter%3A+'
          4        PRE_INC_STATIC_PROP                                  ~1      'counter'
          5        ECHO                                                         ~1
          6        ECHO                                                         '%0A'
   16     7        INIT_FCALL                                                   'rand'
          8        SEND_VAL                                                     1
          9        SEND_VAL                                                     100
         10        DO_ICALL                                             $3      
         11        CAST                                              6  ~4      $3
         12        ASSIGN_OBJ                                                   'value'
         13        OP_DATA                                                      ~4
   17    14      > RETURN                                                       null

End of function __construct

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  run
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                          ~0      'closure'
          1        INIT_METHOD_CALL                                             ~0, 'call'
          2        FETCH_THIS                                           $1      
          3        SEND_VAR_EX                                                  $1
          4        DO_FCALL                                          0          
   22     5      > RETURN                                                       null

End of function run

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smcDi
function name:  __destruct
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   ECHO                                                         'Strategy+Counter%3A+'
          1        PRE_DEC_STATIC_PROP                                  ~0      'counter'
          2        ECHO                                                         ~0
          3        ECHO                                                         '%0A'
   27     4      > RETURN                                                       null

End of function __destruct

End of class Strategy.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.41 ms | 1320 KiB | 14 Q