3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $x; } function id_from_prop(object $obj, string $prop) { $id = (ReflectionReference::fromArrayElement((array) $obj, $prop))?->getId(); return $id ? bin2hex($id) : null; } $foo = new Foo(); $x = 42; $foo->x = &$x; var_dump(id_from_prop($foo, 'x')); var_dump(id_from_prop($foo, 'x')); $y = &$z; var_dump(id_from_prop($foo, 'x'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DXVnX
function name:  (null)
number of ops:  29
compiled vars:  !0 = $foo, !1 = $x, !2 = $y, !3 = $z
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $4      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   13     3        ASSIGN                                                   !1, 42
   14     4        ASSIGN_OBJ_REF                                           !0, 'x'
          5        OP_DATA                                                  !1
   15     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'id_from_prop'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'x'
         10        DO_FCALL                                      0  $9      
         11        SEND_VAR                                                 $9
         12        DO_ICALL                                                 
   16    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'id_from_prop'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 'x'
         17        DO_FCALL                                      0  $11     
         18        SEND_VAR                                                 $11
         19        DO_ICALL                                                 
   17    20        ASSIGN_REF                                               !2, !3
   18    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'id_from_prop'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 'x'
         25        DO_FCALL                                      0  $14     
         26        SEND_VAR                                                 $14
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Function id_from_prop:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DXVnX
function name:  id_from_prop
number of ops:  20
compiled vars:  !0 = $obj, !1 = $prop, !2 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_STATIC_METHOD_CALL                                  'ReflectionReference', 'fromArrayElement'
          3        CAST                                          7  ~3      !0
          4        SEND_VAL                                                 ~3
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        JMP_NULL                                         $5      $4
          8        INIT_METHOD_CALL                                         $4, 'getId'
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !2, $5
    9    11      > JMPZ                                                     !2, ->17
         12    >   INIT_FCALL                                               'bin2hex'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $7      
         15        QM_ASSIGN                                        ~8      $7
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~8      null
         18    > > RETURN                                                   ~8
   10    19*     > RETURN                                                   null

End of function id_from_prop

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.38 ms | 1018 KiB | 18 Q