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) { if (!property_exists($node, $prop)) { $val = null; break; } $node = $node->$prop; $val = $node->$prop; } return $val; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oPVYQ
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
   29    25      > RETURN                                                   1

Function string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 10
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 10
Branch analysis from position: 28
Branch analysis from position: 10
filename:       /in/oPVYQ
function name:  string
number of ops:  30
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                                                      ->22
   19    10    >   INIT_FCALL                                               'property_exists'
         11        SEND_VAR                                                 !4
         12        SEND_VAR                                                 !5
         13        DO_ICALL                                         $10     
         14        BOOL_NOT                                         ~11     $10
         15      > JMPZ                                                     ~11, ->18
   20    16    >   ASSIGN                                                   !2, null
   21    17      > JMP                                                      ->28
   24    18    >   FETCH_OBJ_R                                      ~13     !4, !5
         19        ASSIGN                                                   !4, ~13
   25    20        FETCH_OBJ_R                                      ~15     !4, !5
         21        ASSIGN                                                   !2, ~15
   18    22    >   INIT_FCALL                                               'array_shift'
         23        SEND_REF                                                 !3
         24        DO_ICALL                                         $17     
         25        ASSIGN                                           ~18     !5, $17
         26        TYPE_CHECK                                  1020          ~18
         27      > JMPNZ                                                    ~19, ->10
   28    28    > > RETURN                                                   !2
   29    29*     > RETURN                                                   null

End of function string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.27 ms | 1400 KiB | 21 Q