3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new stdClass(); $obj->name = 'Fred'; $obj->job = new stdClass(); $obj->job->position = 'Janitor'; $obj->job->years = 4; print_r($obj); echo 'Years in current job: '.string($obj, 'job->years').PHP_EOL; function string($obj, $path_str) { $val = null; $path = preg_split('/->/', $path_str); $node = $obj; while (($prop = array_shift($path)) !== null) { print_r($node); echo 'Property exists: '.$prop; if (!property_exists($node, $prop)) { $val = null; break; } $val = $node->$prop; $node = $node->$prop; } return $val; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eaBFC
function name:  (null)
number of ops:  26
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   NEW                                              $1      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
    3     3        ASSIGN_OBJ                                               !0, 'name'
          4        OP_DATA                                                  'Fred'
    4     5        NEW                                              $6      'stdClass'
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               !0, 'job'
          8        OP_DATA                                                  $6
    5     9        FETCH_OBJ_W                                      $8      !0, 'job'
         10        ASSIGN_OBJ                                               $8, 'position'
         11        OP_DATA                                                  'Janitor'
    6    12        FETCH_OBJ_W                                      $10     !0, 'job'
         13        ASSIGN_OBJ                                               $10, 'years'
         14        OP_DATA                                                  4
    7    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
   10    18        INIT_FCALL_BY_NAME                                       'string'
         19        SEND_VAR_EX                                              !0
         20        SEND_VAL_EX                                              'job-%3Eyears'
         21        DO_FCALL                                      0  $13     
         22        CONCAT                                           ~14     'Years+in+current+job%3A+', $13
         23        CONCAT                                           ~15     ~14, '%0A'
         24        ECHO                                                     ~15
   32    25      > RETURN                                                   1

Function string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 10
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 10
Branch analysis from position: 33
Branch analysis from position: 10
filename:       /in/eaBFC
function name:  string
number of ops:  35
compiled vars:  !0 = $obj, !1 = $path_str, !2 = $val, !3 = $path, !4 = $node, !5 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        ASSIGN                                                   !2, null
   16     3        INIT_FCALL                                               'preg_split'
          4        SEND_VAL                                                 '%2F-%3E%2F'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !3, $7
   17     8        ASSIGN                                                   !4, !0
   18     9      > JMP                                                      ->27
   19    10    >   INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !4
         12        DO_ICALL                                                 
   20    13        CONCAT                                           ~11     'Property+exists%3A+', !5
         14        ECHO                                                     ~11
   21    15        INIT_FCALL                                               'property_exists'
         16        SEND_VAR                                                 !4
         17        SEND_VAR                                                 !5
         18        DO_ICALL                                         $12     
         19        BOOL_NOT                                         ~13     $12
         20      > JMPZ                                                     ~13, ->23
   22    21    >   ASSIGN                                                   !2, null
   23    22      > JMP                                                      ->33
   26    23    >   FETCH_OBJ_R                                      ~15     !4, !5
         24        ASSIGN                                                   !2, ~15
   27    25        FETCH_OBJ_R                                      ~17     !4, !5
         26        ASSIGN                                                   !4, ~17
   18    27    >   INIT_FCALL                                               'array_shift'
         28        SEND_REF                                                 !3
         29        DO_ICALL                                         $19     
         30        ASSIGN                                           ~20     !5, $19
         31        TYPE_CHECK                                  1020          ~20
         32      > JMPNZ                                                    ~21, ->10
   31    33    > > RETURN                                                   !2
   32    34*     > RETURN                                                   null

End of function string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.49 ms | 1400 KiB | 21 Q