3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DebugHelper { public function mapShallow($value, int $maxDepth, &$seenObjects = []) { if (is_object($value)) { $oid = spl_object_id($value); $className = get_class($value) . '#' . $oid; if ($seenObjects[$oid] ?? false) { return '**recursive class: ' . $className . '**'; } $seenObjects[$oid] = true; if ($maxDepth <= 0) { return '**class: ' . $className . '**'; } $value = array_merge(['**class**' => $className], (array) $value); } elseif (!is_array($value)) { return $value; } if ($maxDepth <= 0) { return '**array of size: ' . count($value) . '**'; } $res = []; $unseenObjects = []; foreach ($value as $k => $v) { if (is_object($v)) { $oid = spl_object_id($v); if (!($seenObjects[$oid] ?? false)) { $unseenObjects[$k] = true; } } $res[$k] = $this->mapShallow($v, -1, $seenObjects); } foreach ($value as $k => $v) { if (!is_object($v) && !is_array($v)) { continue; } $seenObjects2 = $seenObjects; if (is_object($v) && ($unseenObjects[$k] ?? false)) { unset($seenObjects2[spl_object_id($v)]); } $res[$k] = $this->mapShallow($v, $maxDepth - 1, $seenObjects2); } return $res; } } $dt = new \DateTime('2000-02-20 10:00'); $arr = [ 'foo', [1, 2, [3]], [$dt], $dt, ]; print_r((new DebugHelper())->mapShallow($arr, 2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uJh5r
function name:  (null)
number of ops:  20
compiled vars:  !0 = $dt, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $2      'DateTime'
          1        SEND_VAL_EX                                              '2000-02-20+10%3A00'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   65     4        INIT_ARRAY                                       ~5      'foo'
          5        ADD_ARRAY_ELEMENT                                ~5      <array>
   67     6        INIT_ARRAY                                       ~6      !0
          7        ADD_ARRAY_ELEMENT                                ~5      ~6
   68     8        ADD_ARRAY_ELEMENT                                ~5      !0
   64     9        ASSIGN                                                   !1, ~5
   71    10        INIT_FCALL                                               'print_r'
         11        NEW                                              $8      'DebugHelper'
         12        DO_FCALL                                      0          
         13        INIT_METHOD_CALL                                         $8, 'mapShallow'
         14        SEND_VAR_EX                                              !1
         15        SEND_VAL_EX                                              2
         16        DO_FCALL                                      0  $10     
         17        SEND_VAR                                                 $10
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Class DebugHelper:
Function mapshallow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 35
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 71
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 71
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 63
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 63
Branch analysis from position: 63
Branch analysis from position: 71
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 104
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 104
Branch analysis from position: 74
2 jumps found. (Code = 46) Position 1 = 78, Position 2 = 81
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 83
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 83
2 jumps found. (Code = 46) Position 1 = 86, Position 2 = 90
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 95
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 95
Branch analysis from position: 90
Branch analysis from position: 81
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
Branch analysis from position: 71
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/uJh5r
function name:  mapShallow
number of ops:  107
compiled vars:  !0 = $value, !1 = $maxDepth, !2 = $seenObjects, !3 = $oid, !4 = $className, !5 = $res, !6 = $unseenObjects, !7 = $v, !8 = $k, !9 = $seenObjects2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
    7     3        TYPE_CHECK                                  256          !0
          4      > JMPZ                                                     ~10, ->35
    8     5    >   INIT_FCALL                                               'spl_object_id'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $11     
          8        ASSIGN                                                   !3, $11
   10     9        GET_CLASS                                        ~13     !0
         10        CONCAT                                           ~14     ~13, '%23'
         11        CONCAT                                           ~15     ~14, !3
         12        ASSIGN                                                   !4, ~15
   12    13        FETCH_DIM_IS                                     ~17     !2, !3
         14        COALESCE                                         ~18     ~17
         15        QM_ASSIGN                                        ~18     <false>
         16      > JMPZ                                                     ~18, ->20
   13    17    >   CONCAT                                           ~19     '%2A%2Arecursive+class%3A+', !4
         18        CONCAT                                           ~20     ~19, '%2A%2A'
         19      > RETURN                                                   ~20
   16    20    >   ASSIGN_DIM                                               !2, !3
         21        OP_DATA                                                  <true>
   18    22        IS_SMALLER_OR_EQUAL                                      !1, 0
         23      > JMPZ                                                     ~22, ->27
   19    24    >   CONCAT                                           ~23     '%2A%2Aclass%3A+', !4
         25        CONCAT                                           ~24     ~23, '%2A%2A'
         26      > RETURN                                                   ~24
   22    27    >   INIT_FCALL                                               'array_merge'
         28        INIT_ARRAY                                       ~25     !4, '%2A%2Aclass%2A%2A'
         29        SEND_VAL                                                 ~25
         30        CAST                                          7  ~26     !0
         31        SEND_VAL                                                 ~26
         32        DO_ICALL                                         $27     
         33        ASSIGN                                                   !0, $27
    7    34      > JMP                                                      ->39
   23    35    >   TYPE_CHECK                                  128  ~29     !0
         36        BOOL_NOT                                         ~30     ~29
         37      > JMPZ                                                     ~30, ->39
   24    38    > > RETURN                                                   !0
   27    39    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         40      > JMPZ                                                     ~31, ->45
   28    41    >   COUNT                                            ~32     !0
         42        CONCAT                                           ~33     '%2A%2Aarray+of+size%3A+', ~32
         43        CONCAT                                           ~34     ~33, '%2A%2A'
         44      > RETURN                                                   ~34
   31    45    >   ASSIGN                                                   !5, <array>
   33    46        ASSIGN                                                   !6, <array>
   34    47      > FE_RESET_R                                       $37     !0, ->71
         48    > > FE_FETCH_R                                       ~38     $37, !7, ->71
         49    >   ASSIGN                                                   !8, ~38
   35    50        TYPE_CHECK                                  256          !7
         51      > JMPZ                                                     ~40, ->63
   36    52    >   INIT_FCALL                                               'spl_object_id'
         53        SEND_VAR                                                 !7
         54        DO_ICALL                                         $41     
         55        ASSIGN                                                   !3, $41
   38    56        FETCH_DIM_IS                                     ~43     !2, !3
         57        COALESCE                                         ~44     ~43
         58        QM_ASSIGN                                        ~44     <false>
         59        BOOL_NOT                                         ~45     ~44
         60      > JMPZ                                                     ~45, ->63
   39    61    >   ASSIGN_DIM                                               !6, !8
         62        OP_DATA                                                  <true>
   43    63    >   INIT_METHOD_CALL                                         'mapShallow'
         64        SEND_VAR_EX                                              !7
         65        SEND_VAL_EX                                              -1
         66        SEND_VAR_EX                                              !2
         67        DO_FCALL                                      0  $48     
         68        ASSIGN_DIM                                               !5, !8
         69        OP_DATA                                                  $48
   34    70      > JMP                                                      ->48
         71    >   FE_FREE                                                  $37
   46    72      > FE_RESET_R                                       $49     !0, ->104
         73    > > FE_FETCH_R                                       ~50     $49, !7, ->104
         74    >   ASSIGN                                                   !8, ~50
   47    75        TYPE_CHECK                                  256  ~52     !7
         76        BOOL_NOT                                         ~53     ~52
         77      > JMPZ_EX                                          ~53     ~53, ->81
         78    >   TYPE_CHECK                                  128  ~54     !7
         79        BOOL_NOT                                         ~55     ~54
         80        BOOL                                             ~53     ~55
         81    > > JMPZ                                                     ~53, ->83
   48    82    > > JMP                                                      ->73
   51    83    >   ASSIGN                                                   !9, !2
   52    84        TYPE_CHECK                                  256  ~57     !7
         85      > JMPZ_EX                                          ~57     ~57, ->90
         86    >   FETCH_DIM_IS                                     ~58     !6, !8
         87        COALESCE                                         ~59     ~58
         88        QM_ASSIGN                                        ~59     <false>
         89        BOOL                                             ~57     ~59
         90    > > JMPZ                                                     ~57, ->95
   53    91    >   INIT_FCALL                                               'spl_object_id'
         92        SEND_VAR                                                 !7
         93        DO_ICALL                                         $60     
         94        UNSET_DIM                                                !9, $60
   56    95    >   INIT_METHOD_CALL                                         'mapShallow'
         96        SEND_VAR_EX                                              !7
         97        SUB                                              ~62     !1, 1
         98        SEND_VAL_EX                                              ~62
         99        SEND_VAR_EX                                              !9
        100        DO_FCALL                                      0  $63     
        101        ASSIGN_DIM                                               !5, !8
        102        OP_DATA                                                  $63
   46   103      > JMP                                                      ->73
        104    >   FE_FREE                                                  $49
   59   105      > RETURN                                                   !5
   60   106*     > RETURN                                                   null

End of function mapshallow

End of class DebugHelper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.13 ms | 1025 KiB | 16 Q