3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExtendedArrayObject extends ArrayObject { function offsetGet($offset) { echo "Called", PHP_EOL; return parent::offsetGet($offset, $array); } } class ExtendedArrayAccess implements ArrayAccess { private $data = array(); function __construct(array $array = array()) { $this->data = $array; } function offsetExists($offset) { return array_key_exists($offset, $this->data); } function offsetGet($offset) { return $this->data[$offset]; } function offsetSet($offset, $value) { $this->data[$offset] = $value; } function offsetUnset($offset) { unset($this->data[$offset]); } } $inputs = array( 'array' => array(), 'ExtendedArrayObject' => new ExtendedArrayObject(), 'ExtendedArrayAccess' => new ExtendedArrayAccess(), ); class Tests { function test_existing_key_with_not_empty_value($array) { $array['foo'] = 1; $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === false, __FUNCTION__, $array); } function test_existing_key_with_empty_value($array) { $array['foo'] = 0; $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === true, __FUNCTION__, $array); } function test_non_existent_key($array) { $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === false, __FUNCTION__, $array); } function test_existing_key_with_null_value($array) { $array['foo'] = null; $this->expect(isset($array['foo']) === false, __FUNCTION__, $array); $this->expect(empty($array['foo']) === true, __FUNCTION__, $array); } private function getType($v) { return is_array($v) ? 'array' : get_class($v); } private function expect($condition, $function, $array) { if (!$condition) { echo $this->getType($array), ' failed ', $function, PHP_EOL; } } } $tests = new Tests; foreach (get_class_methods($tests) as $test) { foreach ($inputs as $structure) { $tests->$test($structure); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 25
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 23
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/7sTlX
function name:  (null)
number of ops:  27
compiled vars:  !0 = $inputs, !1 = $tests, !2 = $test, !3 = $structure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'extendedarrayaccess'
   30     1        INIT_ARRAY                                       ~4      <array>, 'array'
   31     2        NEW                                              $5      'ExtendedArrayObject'
          3        DO_FCALL                                      0          
          4        ADD_ARRAY_ELEMENT                                ~4      $5, 'ExtendedArrayObject'
   32     5        NEW                                              $7      'ExtendedArrayAccess'
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~4      $7, 'ExtendedArrayAccess'
   29     8        ASSIGN                                                   !0, ~4
   70     9        NEW                                              $10     'Tests'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $10
   71    12        INIT_FCALL                                               'get_class_methods'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $13     
         15      > FE_RESET_R                                       $14     $13, ->25
         16    > > FE_FETCH_R                                               $14, !2, ->25
   72    17    > > FE_RESET_R                                       $15     !0, ->23
         18    > > FE_FETCH_R                                               $15, !3, ->23
   73    19    >   INIT_METHOD_CALL                                         !1, !2
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0          
   72    22      > JMP                                                      ->18
         23    >   FE_FREE                                                  $15
   71    24      > JMP                                                      ->16
         25    >   FE_FREE                                                  $14
   75    26      > RETURN                                                   1

Class ExtendedArrayObject:
Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  offsetGet
number of ops:  9
compiled vars:  !0 = $offset, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ECHO                                                     'Called'
          2        ECHO                                                     '%0A'
    6     3        INIT_STATIC_METHOD_CALL                                  'offsetGet'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
    7     8*     > RETURN                                                   null

End of function offsetget

End of class ExtendedArrayObject.

Class ExtendedArrayAccess:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  __construct
number of ops:  4
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV_INIT                                        !0      <array>
   13     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        FETCH_OBJ_R                                      ~1      'data'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3      > RETURN                                                   ~2
   17     4*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  offsetGet
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        FETCH_OBJ_R                                      ~1      'data'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   20     4*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  offsetSet
number of ops:  6
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   23     5      > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_UNSET                                  $1      'data'
          2        UNSET_DIM                                                $1, !0
   26     3      > RETURN                                                   null

End of function offsetunset

End of class ExtendedArrayAccess.

Class Tests:
Function test_existing_key_with_not_empty_value:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  test_existing_key_with_not_empty_value
number of ops:  18
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        ASSIGN_DIM                                               !0, 'foo'
          2        OP_DATA                                                  1
   38     3        INIT_METHOD_CALL                                         'expect'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      !0, 'foo'
          5        TYPE_CHECK                                    8  ~3      ~2
          6        SEND_VAL_EX                                              ~3
          7        SEND_VAL_EX                                              'test_existing_key_with_not_empty_value'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   39    10        INIT_METHOD_CALL                                         'expect'
         11        ISSET_ISEMPTY_DIM_OBJ                         1  ~5      !0, 'foo'
         12        TYPE_CHECK                                    4  ~6      ~5
         13        SEND_VAL_EX                                              ~6
         14        SEND_VAL_EX                                              'test_existing_key_with_not_empty_value'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
   40    17      > RETURN                                                   null

End of function test_existing_key_with_not_empty_value

Function test_existing_key_with_empty_value:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  test_existing_key_with_empty_value
number of ops:  18
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        ASSIGN_DIM                                               !0, 'foo'
          2        OP_DATA                                                  0
   44     3        INIT_METHOD_CALL                                         'expect'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      !0, 'foo'
          5        TYPE_CHECK                                    8  ~3      ~2
          6        SEND_VAL_EX                                              ~3
          7        SEND_VAL_EX                                              'test_existing_key_with_empty_value'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   45    10        INIT_METHOD_CALL                                         'expect'
         11        ISSET_ISEMPTY_DIM_OBJ                         1  ~5      !0, 'foo'
         12        TYPE_CHECK                                    8  ~6      ~5
         13        SEND_VAL_EX                                              ~6
         14        SEND_VAL_EX                                              'test_existing_key_with_empty_value'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
   46    17      > RETURN                                                   null

End of function test_existing_key_with_empty_value

Function test_non_existent_key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  test_non_existent_key
number of ops:  16
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1        INIT_METHOD_CALL                                         'expect'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~1      !0, 'foo'
          3        TYPE_CHECK                                    8  ~2      ~1
          4        SEND_VAL_EX                                              ~2
          5        SEND_VAL_EX                                              'test_non_existent_key'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
   50     8        INIT_METHOD_CALL                                         'expect'
          9        ISSET_ISEMPTY_DIM_OBJ                         1  ~4      !0, 'foo'
         10        TYPE_CHECK                                    4  ~5      ~4
         11        SEND_VAL_EX                                              ~5
         12        SEND_VAL_EX                                              'test_non_existent_key'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
   51    15      > RETURN                                                   null

End of function test_non_existent_key

Function test_existing_key_with_null_value:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  test_existing_key_with_null_value
number of ops:  18
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        ASSIGN_DIM                                               !0, 'foo'
          2        OP_DATA                                                  null
   55     3        INIT_METHOD_CALL                                         'expect'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      !0, 'foo'
          5        TYPE_CHECK                                    4  ~3      ~2
          6        SEND_VAL_EX                                              ~3
          7        SEND_VAL_EX                                              'test_existing_key_with_null_value'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   56    10        INIT_METHOD_CALL                                         'expect'
         11        ISSET_ISEMPTY_DIM_OBJ                         1  ~5      !0, 'foo'
         12        TYPE_CHECK                                    8  ~6      ~5
         13        SEND_VAL_EX                                              ~6
         14        SEND_VAL_EX                                              'test_existing_key_with_null_value'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
   57    17      > RETURN                                                   null

End of function test_existing_key_with_null_value

Function gettype:
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 = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7sTlX
function name:  getType
number of ops:  9
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   60     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~1, ->5
          3    >   QM_ASSIGN                                        ~2      'array'
          4      > JMP                                                      ->7
          5    >   GET_CLASS                                        ~3      !0
          6        QM_ASSIGN                                        ~2      ~3
          7    > > RETURN                                                   ~2
   61     8*     > RETURN                                                   null

End of function gettype

Function expect:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/7sTlX
function name:  expect
number of ops:  13
compiled vars:  !0 = $condition, !1 = $function, !2 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   64     3        BOOL_NOT                                         ~3      !0
          4      > JMPZ                                                     ~3, ->12
   65     5    >   INIT_METHOD_CALL                                         'getType'
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
          9        ECHO                                                     '+failed+'
         10        ECHO                                                     !1
         11        ECHO                                                     '%0A'
   67    12    > > RETURN                                                   null

End of function expect

End of class Tests.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.32 ms | 1404 KiB | 15 Q