3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getGrandParentClass($object, $level = NULL) { $gp = $object = get_class($object); $isNull = is_null($level); $j = 0; while(get_parent_class($gp) && ($isNull || $level > $j)) { $gp = get_parent_class($gp); $j++; if(!get_parent_class($gp) && !$isNull && $level > $j) return false; } return $gp == $object ? false : $gp; } class A {} class B extends A {} class C extends B {} class D extends C {} var_dump(getGrandParentClass(new A())); // false var_dump(getGrandParentClass(new D(), 0));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FOLh6
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'getgrandparentclass'
          2        NEW                                              $0      'A'
          3        DO_FCALL                                      0          
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   28     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'getgrandparentclass'
         10        NEW                                              $4      'D'
         11        DO_FCALL                                      0          
         12        SEND_VAR                                                 $4
         13        SEND_VAL                                                 0
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function getgrandparentclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
2 jumps found. (Code = 47) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 9
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 24
Branch analysis from position: 21
Branch analysis from position: 33
Branch analysis from position: 34
filename:       /in/FOLh6
function name:  getGrandParentClass
number of ops:  42
compiled vars:  !0 = $object, !1 = $level, !2 = $gp, !3 = $isNull, !4 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        GET_CLASS                                        ~5      !0
          3        ASSIGN                                           ~6      !0, ~5
          4        ASSIGN                                                   !2, ~6
    6     5        TYPE_CHECK                                    2  ~8      !1
          6        ASSIGN                                                   !3, ~8
    7     7        ASSIGN                                                   !4, 0
    9     8      > JMP                                                      ->26
   11     9    >   INIT_FCALL                                               'get_parent_class'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !2, $11
   12    13        PRE_INC                                                  !4
   14    14        INIT_FCALL                                               'get_parent_class'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $14     
         17        BOOL_NOT                                         ~15     $14
         18      > JMPZ_EX                                          ~15     ~15, ->21
         19    >   BOOL_NOT                                         ~16     !3
         20        BOOL                                             ~15     ~16
         21    > > JMPZ_EX                                          ~15     ~15, ->24
         22    >   IS_SMALLER                                       ~17     !4, !1
         23        BOOL                                             ~15     ~17
         24    > > JMPZ                                                     ~15, ->26
   15    25    > > RETURN                                                   <false>
    9    26    >   INIT_FCALL                                               'get_parent_class'
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $18     
         29      > JMPZ_EX                                          ~19     $18, ->34
         30    > > JMPNZ_EX                                         ~20     !3, ->33
         31    >   IS_SMALLER                                       ~21     !4, !1
         32        BOOL                                             ~20     ~21
         33    >   BOOL                                             ~19     ~20
         34    > > JMPNZ                                                    ~19, ->9
   18    35    >   IS_EQUAL                                                 !2, !0
         36      > JMPZ                                                     ~22, ->39
         37    >   QM_ASSIGN                                        ~23     <false>
         38      > JMP                                                      ->40
         39    >   QM_ASSIGN                                        ~23     !2
         40    > > RETURN                                                   ~23
   19    41*     > RETURN                                                   null

End of function getgrandparentclass

Class A: [no user functions]
Class B: [no user functions]
Class C: [no user functions]
Class D: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.84 ms | 1402 KiB | 19 Q