3v4l.org

run code in 300+ PHP versions simultaneously
<?php class State { protected $foo; protected $bar; public function getFoo() { return $this->foo; } public function getBar() { return $this->bar; } public final function setFoo($foo) { $this->foo = $foo; } public final function setBar($bar) { $this->bar = $bar; } public final function transaction(callable $function) { $proxy = new StateProxy($this); if (call_user_func($function, $proxy)) { $proxy->commit(); } unset($proxy); } } class StateProxy extends State { protected $state; public function __construct(State $state) { $this->state = $state; } public function getFoo() { return parent::getFoo() ? : $this->state->getFoo(); } public function getBar() { return parent::getBar() ? : $this->state->getBar(); } public function commit() { $this->state->foo = $this->foo; $this->state->bar = $this->bar; } } $state = new State(); $state->setFoo('abc'); $state->setBar('123'); var_dump($state); $state->transaction(function(StateProxy $proxy) { $proxy->setFoo('def'); $proxy->setBar('456'); return true; }); var_dump($state); $state->transaction(function(StateProxy $proxy) { $proxy->setFoo('ghi'); $proxy->setBar('789'); return false; }); var_dump($state); $state = new State(); $state->setFoo('abc'); $state->setBar('123'); $state->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('def'); $proxy->setBar('456'); return false; }); $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('ghi'); $proxy->setBar('789'); return true; }); return true; }); $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('jkl'); $proxy->setBar('012'); return false; }); return true; }); return true; }); var_dump($state);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  (null)
number of ops:  43
compiled vars:  !0 = $state
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   NEW                                              $1      'State'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   58     3        INIT_METHOD_CALL                                         !0, 'setFoo'
          4        SEND_VAL_EX                                              'abc'
          5        DO_FCALL                                      0          
   59     6        INIT_METHOD_CALL                                         !0, 'setBar'
          7        SEND_VAL_EX                                              '123'
          8        DO_FCALL                                      0          
   60     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
   62    12        INIT_METHOD_CALL                                         !0, 'transaction'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A62%240'
   66    14        SEND_VAL_EX                                              ~7
         15        DO_FCALL                                      0          
   67    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
   69    19        INIT_METHOD_CALL                                         !0, 'transaction'
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A69%241'
   73    21        SEND_VAL_EX                                              ~10
         22        DO_FCALL                                      0          
   74    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
   77    26        NEW                                              $13     'State'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !0, $13
   78    29        INIT_METHOD_CALL                                         !0, 'setFoo'
         30        SEND_VAL_EX                                              'abc'
         31        DO_FCALL                                      0          
   79    32        INIT_METHOD_CALL                                         !0, 'setBar'
         33        SEND_VAL_EX                                              '123'
         34        DO_FCALL                                      0          
   81    35        INIT_METHOD_CALL                                         !0, 'transaction'
         36        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A81%242'
  104    37        SEND_VAL_EX                                              ~18
         38        DO_FCALL                                      0          
  105    39        INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A62%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        INIT_METHOD_CALL                                         !0, 'setFoo'
          2        SEND_VAL_EX                                              'def'
          3        DO_FCALL                                      0          
   64     4        INIT_METHOD_CALL                                         !0, 'setBar'
          5        SEND_VAL_EX                                              '456'
          6        DO_FCALL                                      0          
   65     7      > RETURN                                                   <true>
   66     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A62%240

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A69%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   70     1        INIT_METHOD_CALL                                         !0, 'setFoo'
          2        SEND_VAL_EX                                              'ghi'
          3        DO_FCALL                                      0          
   71     4        INIT_METHOD_CALL                                         !0, 'setBar'
          5        SEND_VAL_EX                                              '789'
          6        DO_FCALL                                      0          
   72     7      > RETURN                                                   <false>
   73     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A69%241

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A81%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
   82     1        INIT_METHOD_CALL                                         !0, 'transaction'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A82%243'
  102     3        SEND_VAL_EX                                              ~1
          4        DO_FCALL                                      0          
  103     5      > RETURN                                                   <true>
  104     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A81%242

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A82%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   83     1        INIT_METHOD_CALL                                         !0, 'transaction'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A83%244'
   95     3        SEND_VAL_EX                                              ~1
          4        DO_FCALL                                      0          
   96     5        INIT_METHOD_CALL                                         !0, 'transaction'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A96%247'
  100     7        SEND_VAL_EX                                              ~3
          8        DO_FCALL                                      0          
  101     9      > RETURN                                                   <true>
  102    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A82%243

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A83%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
   84     1        INIT_METHOD_CALL                                         !0, 'transaction'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A84%245'
   88     3        SEND_VAL_EX                                              ~1
          4        DO_FCALL                                      0          
   89     5        INIT_METHOD_CALL                                         !0, 'transaction'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBfmpQ%3A89%246'
   93     7        SEND_VAL_EX                                              ~3
          8        DO_FCALL                                      0          
   94     9      > RETURN                                                   <true>
   95    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A83%244

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A84%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
   85     1        INIT_METHOD_CALL                                         !0, 'setFoo'
          2        SEND_VAL_EX                                              'def'
          3        DO_FCALL                                      0          
   86     4        INIT_METHOD_CALL                                         !0, 'setBar'
          5        SEND_VAL_EX                                              '456'
          6        DO_FCALL                                      0          
   87     7      > RETURN                                                   <false>
   88     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A84%245

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A89%246:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
   90     1        INIT_METHOD_CALL                                         !0, 'setFoo'
          2        SEND_VAL_EX                                              'ghi'
          3        DO_FCALL                                      0          
   91     4        INIT_METHOD_CALL                                         !0, 'setBar'
          5        SEND_VAL_EX                                              '789'
          6        DO_FCALL                                      0          
   92     7      > RETURN                                                   <true>
   93     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A89%246

Function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A96%247:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
   97     1        INIT_METHOD_CALL                                         !0, 'setFoo'
          2        SEND_VAL_EX                                              'jkl'
          3        DO_FCALL                                      0          
   98     4        INIT_METHOD_CALL                                         !0, 'setBar'
          5        SEND_VAL_EX                                              '012'
          6        DO_FCALL                                      0          
   99     7      > RETURN                                                   <false>
  100     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBfmpQ%3A96%247

Class State:
Function getfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  getFoo
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'foo'
          1      > RETURN                                                   ~0
   10     2*     > RETURN                                                   null

End of function getfoo

Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  getBar
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1      > RETURN                                                   ~0
   14     2*     > RETURN                                                   null

End of function getbar

Function setfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  setFoo
number of ops:  4
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN_OBJ                                               'foo'
          2        OP_DATA                                                  !0
   18     3      > RETURN                                                   null

End of function setfoo

Function setbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  setBar
number of ops:  4
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   22     3      > RETURN                                                   null

End of function setbar

Function transaction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/BfmpQ
function name:  transaction
number of ops:  14
compiled vars:  !0 = $function, !1 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        NEW                                              $2      'StateProxy'
          2        FETCH_THIS                                       $3      
          3        SEND_VAR_EX                                              $3
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $2
   26     6        INIT_USER_CALL                                1          'call_user_func', !0
          7        SEND_USER                                                !1
          8        DO_FCALL                                      0  $6      
          9      > JMPZ                                                     $6, ->12
   27    10    >   INIT_METHOD_CALL                                         !1, 'commit'
         11        DO_FCALL                                      0          
   29    12    >   UNSET_CV                                                 !1
   30    13      > RETURN                                                   null

End of function transaction

End of class State.

Class StateProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $state
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        ASSIGN_OBJ                                               'state'
          2        OP_DATA                                                  !0
   40     3      > RETURN                                                   null

End of function __construct

Function getfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  getFoo
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_STATIC_METHOD_CALL                                  'getFoo'
          1        DO_FCALL                                      0  $0      
          2        JMP_SET                                          ~1      $0, ->7
          3        FETCH_OBJ_R                                      ~2      'state'
          4        INIT_METHOD_CALL                                         ~2, 'getFoo'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~1      $3
          7      > RETURN                                                   ~1
   44     8*     > RETURN                                                   null

End of function getfoo

Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  getBar
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_STATIC_METHOD_CALL                                  'getBar'
          1        DO_FCALL                                      0  $0      
          2        JMP_SET                                          ~1      $0, ->7
          3        FETCH_OBJ_R                                      ~2      'state'
          4        INIT_METHOD_CALL                                         ~2, 'getBar'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~1      $3
          7      > RETURN                                                   ~1
   48     8*     > RETURN                                                   null

End of function getbar

Function commit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  commit
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~2      'foo'
          1        FETCH_OBJ_W                                      $0      'state'
          2        ASSIGN_OBJ                                               $0, 'foo'
          3        OP_DATA                                                  ~2
   52     4        FETCH_OBJ_R                                      ~5      'bar'
          5        FETCH_OBJ_W                                      $3      'state'
          6        ASSIGN_OBJ                                               $3, 'bar'
          7        OP_DATA                                                  ~5
   53     8      > RETURN                                                   null

End of function commit

Function setfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  setFoo
number of ops:  4
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN_OBJ                                               'foo'
          2        OP_DATA                                                  !0
   18     3      > RETURN                                                   null

End of function setfoo

Function setbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BfmpQ
function name:  setBar
number of ops:  4
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   22     3      > RETURN                                                   null

End of function setbar

Function transaction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/BfmpQ
function name:  transaction
number of ops:  14
compiled vars:  !0 = $function, !1 = $proxy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        NEW                                              $2      'StateProxy'
          2        FETCH_THIS                                       $3      
          3        SEND_VAR_EX                                              $3
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $2
   26     6        INIT_USER_CALL                                1          'call_user_func', !0
          7        SEND_USER                                                !1
          8        DO_FCALL                                      0  $6      
          9      > JMPZ                                                     $6, ->12
   27    10    >   INIT_METHOD_CALL                                         !1, 'commit'
         11        DO_FCALL                                      0          
   29    12    >   UNSET_CV                                                 !1
   30    13      > RETURN                                                   null

End of function transaction

End of class StateProxy.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.48 ms | 1420 KiB | 15 Q