3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LegacyBank { protected $clients; protected $balances; public function __construct($clients, $balances) { $this->clients = $clients; $this->balances = $balances; } public function getClientIndex($name) { foreach ($clients as $key => $client) { if ($client == $name) { $id = $key; break; } } return $id; } public function getBalance($index) { return $this->balances[$index]; } public function setBalance($index, $value) { $this->balances[$index] = $value; } public function processTransfer($id1, $sum, $id2) { $this->balances[$id1] = $this->balances[$id1] - $sum; $this->balances[$id2] = $this->balances[$id2] + $sum; } } interface POOClient{ public function deposit($sum); public function verifyAccount(); public function transfer($sum, $destination); } class SimpleClient implements POOClient{ protected $name; protected $legacyBank; protected $index; public function __construct($name, $legacyBank) { $this->name = $name; $this->legacyBank = $legacyBank; $this->index = $legacyBank->getClient($name); } public function deposit($sum) { $legacybank->setBalance($this->index, $sum); } public function verifyAccount() { $sum = $legacyBank->getBalance($this->index); return $sum; } public function transfer($sum, $destination) { $toIndex = $legacyBank->getClient($destination); $this->legacyBank->setBalance($toIndex, $sum); $oldBalance = $this->legacybank->getBalance($this->index); $this->legacyBank->setBalance($this->index, $oldBalance - $sum); } } $clients = array( '0' => 'Ion', '1' => 'Maria', '2' => 'Costel' ); $balances = array( '0' => 1000, '1' => 1400, '2' => 1300 ); $legacyBank = new LegacyBank($clients, $balances); $clientObject = new SimpleClient('Ion', $legacyBank); print_t($clientObject);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  (null)
number of ops:  17
compiled vars:  !0 = $clients, !1 = $balances, !2 = $legacyBank, !3 = $clientObject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   DECLARE_CLASS                                            'simpleclient'
   78     1        ASSIGN                                                   !0, <array>
   83     2        ASSIGN                                                   !1, <array>
   88     3        NEW                                              $6      'LegacyBank'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   90     8        NEW                                              $9      'SimpleClient'
          9        SEND_VAL_EX                                              'Ion'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $9
   92    13        INIT_FCALL_BY_NAME                                       'print_t'
         14        SEND_VAR_EX                                              !3
         15        DO_FCALL                                      0          
         16      > RETURN                                                   1

Class LegacyBank:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  __construct
number of ops:  7
compiled vars:  !0 = $clients, !1 = $balances
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        ASSIGN_OBJ                                               'clients'
          3        OP_DATA                                                  !0
   10     4        ASSIGN_OBJ                                               'balances'
          5        OP_DATA                                                  !1
   11     6      > RETURN                                                   null

End of function __construct

Function getclientindex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
Branch analysis from position: 9
filename:       /in/9u9W7
function name:  getClientIndex
number of ops:  12
compiled vars:  !0 = $name, !1 = $clients, !2 = $client, !3 = $key, !4 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1      > FE_RESET_R                                       $5      !1, ->9
          2    > > FE_FETCH_R                                       ~6      $5, !2, ->9
          3    >   ASSIGN                                                   !3, ~6
   15     4        IS_EQUAL                                                 !2, !0
          5      > JMPZ                                                     ~8, ->8
   16     6    >   ASSIGN                                                   !4, !3
   17     7      > JMP                                                      ->9
   14     8    > > JMP                                                      ->2
          9    >   FE_FREE                                                  $5
   20    10      > RETURN                                                   !4
   21    11*     > RETURN                                                   null

End of function getclientindex

Function getbalance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  getBalance
number of ops:  5
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~1      'balances'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   25     4*     > RETURN                                                   null

End of function getbalance

Function setbalance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  setBalance
number of ops:  6
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        FETCH_OBJ_W                                      $2      'balances'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   29     5      > RETURN                                                   null

End of function setbalance

Function processtransfer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  processTransfer
number of ops:  16
compiled vars:  !0 = $id1, !1 = $sum, !2 = $id2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   32     3        FETCH_OBJ_R                                      ~5      'balances'
          4        FETCH_DIM_R                                      ~6      ~5, !0
          5        SUB                                              ~7      ~6, !1
          6        FETCH_OBJ_W                                      $3      'balances'
          7        ASSIGN_DIM                                               $3, !0
          8        OP_DATA                                                  ~7
   33     9        FETCH_OBJ_R                                      ~10     'balances'
         10        FETCH_DIM_R                                      ~11     ~10, !2
         11        ADD                                              ~12     ~11, !1
         12        FETCH_OBJ_W                                      $8      'balances'
         13        ASSIGN_DIM                                               $8, !2
         14        OP_DATA                                                  ~12
   34    15      > RETURN                                                   null

End of function processtransfer

End of class LegacyBank.

Class POOClient:
Function deposit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  deposit
number of ops:  2
compiled vars:  !0 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function deposit

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

End of function verifyaccount

Function transfer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  transfer
number of ops:  3
compiled vars:  !0 = $sum, !1 = $destination
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > RETURN                                                   null

End of function transfer

End of class POOClient.

Class SimpleClient:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  __construct
number of ops:  12
compiled vars:  !0 = $name, !1 = $legacyBank
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   49     2        ASSIGN_OBJ                                               'name'
          3        OP_DATA                                                  !0
   50     4        ASSIGN_OBJ                                               'legacyBank'
          5        OP_DATA                                                  !1
   52     6        INIT_METHOD_CALL                                         !1, 'getClient'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $5      
          9        ASSIGN_OBJ                                               'index'
         10        OP_DATA                                                  $5
   53    11      > RETURN                                                   null

End of function __construct

Function deposit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  deposit
number of ops:  8
compiled vars:  !0 = $sum, !1 = $legacybank
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   57     1        INIT_METHOD_CALL                                         !1, 'setBalance'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $2      'index'
          4        SEND_FUNC_ARG                                            $2
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   58     7      > RETURN                                                   null

End of function deposit

Function verifyaccount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  verifyAccount
number of ops:  8
compiled vars:  !0 = $sum, !1 = $legacyBank
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_METHOD_CALL                                         !1, 'getBalance'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $2      'index'
          3        SEND_FUNC_ARG                                            $2
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   64     6      > RETURN                                                   !0
   65     7*     > RETURN                                                   null

End of function verifyaccount

Function transfer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9u9W7
function name:  transfer
number of ops:  27
compiled vars:  !0 = $sum, !1 = $destination, !2 = $toIndex, !3 = $legacyBank, !4 = $oldBalance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   69     2        INIT_METHOD_CALL                                         !3, 'getClient'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !2, $5
   71     6        FETCH_OBJ_R                                      ~7      'legacyBank'
          7        INIT_METHOD_CALL                                         ~7, 'setBalance'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
   73    11        FETCH_OBJ_R                                      ~9      'legacybank'
         12        INIT_METHOD_CALL                                         ~9, 'getBalance'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_OBJ_FUNC_ARG                               $10     'index'
         15        SEND_FUNC_ARG                                            $10
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !4, $11
   74    18        FETCH_OBJ_R                                      ~13     'legacyBank'
         19        INIT_METHOD_CALL                                         ~13, 'setBalance'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $14     'index'
         22        SEND_FUNC_ARG                                            $14
         23        SUB                                              ~15     !4, !0
         24        SEND_VAL_EX                                              ~15
         25        DO_FCALL                                      0          
   75    26      > RETURN                                                   null

End of function transfer

End of class SimpleClient.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.74 ms | 1411 KiB | 13 Q