3v4l.org

run code in 300+ PHP versions simultaneously
<?php $wp_version = '6.2.0'; // WP Core code. class Foo { public function __call( $name, $arguments ) { if ( 'new_method_A' === $name || 'new_method_B' === $name || 'new_method_C' === $name ) { return $this->$name( ...$arguments ); } $class = get_class( $this ); $trace = debug_backtrace(); $file = $trace[0]['file']; $line = $trace[0]['line']; trigger_error( "Call to undefined method $class::$name() in $file on line $line", E_USER_ERROR ); } private function new_method_A() { echo __FUNCTION__, ' called!', PHP_EOL; } private function new_method_B() { echo __FUNCTION__, ' called!', PHP_EOL; } public function new_method_C() { echo __FUNCTION__, ' called!', PHP_EOL; } } // Plugin code. $obj = new Foo(); if (method_exists($obj, 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (method_exists('Foo', 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (is_callable($obj, 'new_method_B')) { $obj->new_method_B(); // NOTE: doesn't work as method is private. } else { // Do it some other way to support older WP versions. } if (version_compare($wp_version, '6.2.0', '>=') === true) { $obj->new_method_C(); } else { // Do it some other way to support older WP versions. }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 28
Branch analysis from position: 20
Branch analysis from position: 12
filename:       /in/PQvYp
function name:  (null)
number of ops:  39
compiled vars:  !0 = $wp_version, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '6.2.0'
   35     1        NEW                                              $3      'Foo'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   36     4        INIT_FCALL                                               'method_exists'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 'new_method_A'
          7        DO_ICALL                                         $6      
          8      > JMPZ                                                     $6, ->12
   37     9    >   INIT_METHOD_CALL                                         !1, 'new_method_A'
         10        DO_FCALL                                      0          
   36    11      > JMP                                                      ->12
   42    12    >   INIT_FCALL                                               'method_exists'
         13        SEND_VAL                                                 'Foo'
         14        SEND_VAL                                                 'new_method_A'
         15        DO_ICALL                                         $8      
         16      > JMPZ                                                     $8, ->20
   43    17    >   INIT_METHOD_CALL                                         !1, 'new_method_A'
         18        DO_FCALL                                      0          
   42    19      > JMP                                                      ->20
   48    20    >   INIT_FCALL                                               'is_callable'
         21        SEND_VAR                                                 !1
         22        SEND_VAL                                                 'new_method_B'
         23        DO_ICALL                                         $10     
         24      > JMPZ                                                     $10, ->28
   49    25    >   INIT_METHOD_CALL                                         !1, 'new_method_B'
         26        DO_FCALL                                      0          
   48    27      > JMP                                                      ->28
   54    28    >   INIT_FCALL                                               'version_compare'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 '6.2.0'
         31        SEND_VAL                                                 '%3E%3D'
         32        DO_ICALL                                         $12     
         33        TYPE_CHECK                                    8          $12
         34      > JMPZ                                                     ~13, ->38
   55    35    >   INIT_METHOD_CALL                                         !1, 'new_method_C'
         36        DO_FCALL                                      0          
   54    37      > JMP                                                      ->38
   58    38    > > RETURN                                                   1

Class Foo:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
Branch analysis from position: 6
filename:       /in/PQvYp
function name:  __call
number of ops:  40
compiled vars:  !0 = $name, !1 = $arguments, !2 = $class, !3 = $trace, !4 = $file, !5 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        IS_IDENTICAL                                     ~6      !0, 'new_method_A'
          3      > JMPNZ_EX                                         ~6      ~6, ->6
    8     4    >   IS_IDENTICAL                                     ~7      !0, 'new_method_B'
          5        BOOL                                             ~6      ~7
          6    > > JMPNZ_EX                                         ~6      ~6, ->9
    9     7    >   IS_IDENTICAL                                     ~8      !0, 'new_method_C'
          8        BOOL                                             ~6      ~8
          9    > > JMPZ                                                     ~6, ->15
   11    10    >   INIT_METHOD_CALL                                         !0
         11        SEND_UNPACK                                              !1
         12        CHECK_UNDEF_ARGS                                         
         13        DO_FCALL                                      1  $9      
         14      > RETURN                                                   $9
   14    15    >   FETCH_THIS                                       ~10     
         16        GET_CLASS                                        ~11     ~10
         17        ASSIGN                                                   !2, ~11
   15    18        INIT_FCALL                                               'debug_backtrace'
         19        DO_ICALL                                         $13     
         20        ASSIGN                                                   !3, $13
   16    21        FETCH_DIM_R                                      ~15     !3, 0
         22        FETCH_DIM_R                                      ~16     ~15, 'file'
         23        ASSIGN                                                   !4, ~16
   17    24        FETCH_DIM_R                                      ~18     !3, 0
         25        FETCH_DIM_R                                      ~19     ~18, 'line'
         26        ASSIGN                                                   !5, ~19
   18    27        INIT_FCALL                                               'trigger_error'
         28        ROPE_INIT                                     8  ~22     'Call+to+undefined+method+'
         29        ROPE_ADD                                      1  ~22     ~22, !2
         30        ROPE_ADD                                      2  ~22     ~22, '%3A%3A'
         31        ROPE_ADD                                      3  ~22     ~22, !0
         32        ROPE_ADD                                      4  ~22     ~22, '%28%29+in+'
         33        ROPE_ADD                                      5  ~22     ~22, !4
         34        ROPE_ADD                                      6  ~22     ~22, '+on+line+'
         35        ROPE_END                                      7  ~21     ~22, !5
         36        SEND_VAL                                                 ~21
         37        SEND_VAL                                                 256
         38        DO_ICALL                                                 
   19    39      > RETURN                                                   null

End of function __call

Function new_method_a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PQvYp
function name:  new_method_A
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ECHO                                                     'new_method_A'
          1        ECHO                                                     '+called%21'
          2        ECHO                                                     '%0A'
   23     3      > RETURN                                                   null

End of function new_method_a

Function new_method_b:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PQvYp
function name:  new_method_B
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ECHO                                                     'new_method_B'
          1        ECHO                                                     '+called%21'
          2        ECHO                                                     '%0A'
   27     3      > RETURN                                                   null

End of function new_method_b

Function new_method_c:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PQvYp
function name:  new_method_C
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ECHO                                                     'new_method_C'
          1        ECHO                                                     '+called%21'
          2        ECHO                                                     '%0A'
   31     3      > RETURN                                                   null

End of function new_method_c

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.54 ms | 1023 KiB | 18 Q