3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected $id; protected $displayName; } class B implements ArrayAccess { protected $id; protected $displayName; public function offsetSet($offset, $value) { $offset = $this->_mapField($offset); $this->$offset = $value; } public function offsetExists($offset) { $offset = $this->_mapField($offset); return isset($this->$offset); } public function offsetUnset($offset) { $offset = $this->_mapField($offset); throw new \Exception("Cannot remove the property $offset"); } public function offsetGet($offset) { $offset = $this->_mapField($offset); if ($this->offsetExists($offset)) { return $this->$offset; } throw new \Exception("$offset property does not exists"); } private function _mapField($keyFrom) { if ($keyFrom === 'id_user') { return 'id'; } elseif ($keyFrom === 'name') { return 'displayName'; } return $keyFrom; } } $b = new B(); var_dump($b['id']); var_dump($b['id_user']); var_dump($b['displayName']); var_dump($b['name']);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89YJo
function name:  (null)
number of ops:  21
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'b'
   55     1        NEW                                              $1      'B'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   57     4        INIT_FCALL                                               'var_dump'
          5        FETCH_DIM_R                                      ~4      !0, 'id'
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   58     8        INIT_FCALL                                               'var_dump'
          9        FETCH_DIM_R                                      ~6      !0, 'id_user'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                                 
   59    12        INIT_FCALL                                               'var_dump'
         13        FETCH_DIM_R                                      ~8      !0, 'displayName'
         14        SEND_VAL                                                 ~8
         15        DO_ICALL                                                 
   60    16        INIT_FCALL                                               'var_dump'
         17        FETCH_DIM_R                                      ~10     !0, 'name'
         18        SEND_VAL                                                 ~10
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Class A: [no user functions]
Class B:
Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89YJo
function name:  offsetSet
number of ops:  9
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        INIT_METHOD_CALL                                         '_mapField'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
   19     6        ASSIGN_OBJ                                               !0
          7        OP_DATA                                                  !1
   20     8      > RETURN                                                   null

End of function offsetset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89YJo
function name:  offsetExists
number of ops:  8
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         '_mapField'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   25     5        ISSET_ISEMPTY_PROP_OBJ                           ~3      !0
          6      > RETURN                                                   ~3
   26     7*     > RETURN                                                   null

End of function offsetexists

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/89YJo
function name:  offsetUnset
number of ops:  12
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         '_mapField'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   31     5        NEW                                              $3      'Exception'
          6        NOP                                                      
          7        FAST_CONCAT                                      ~4      'Cannot+remove+the+property+', !0
          8        SEND_VAL_EX                                              ~4
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $3
   32    11*     > RETURN                                                   null

End of function offsetunset

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/89YJo
function name:  offsetGet
number of ops:  18
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        INIT_METHOD_CALL                                         '_mapField'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   37     5        INIT_METHOD_CALL                                         'offsetExists'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $3      
          8      > JMPZ                                                     $3, ->11
   38     9    >   FETCH_OBJ_R                                      ~4      !0
         10      > RETURN                                                   ~4
   40    11    >   NEW                                              $5      'Exception'
         12        NOP                                                      
         13        FAST_CONCAT                                      ~6      !0, '+property+does+not+exists'
         14        SEND_VAL_EX                                              ~6
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $5
   41    17*     > RETURN                                                   null

End of function offsetget

Function _mapfield:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89YJo
function name:  _mapField
number of ops:  10
compiled vars:  !0 = $keyFrom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        IS_IDENTICAL                                             !0, 'id_user'
          2      > JMPZ                                                     ~1, ->5
   46     3    > > RETURN                                                   'id'
          4*       JMP                                                      ->8
   47     5    >   IS_IDENTICAL                                             !0, 'name'
          6      > JMPZ                                                     ~2, ->8
   48     7    > > RETURN                                                   'displayName'
   51     8    > > RETURN                                                   !0
   52     9*     > RETURN                                                   null

End of function _mapfield

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.88 ms | 1396 KiB | 15 Q