3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { function test() { echo 'foo test'; } } class Bar { function test() { echo 'bar test'; } } $foo = new Foo(); $foo = change_class($foo, 'Bar'); $foo->test(); function change_class($object, $new_class) { preg_match('~^O:[0-9]+:"[^"]+":(.+)$~', serialize($object), $matches); return unserialize(sprintf('O:%s:"%s":%s', strlen($new_class), $new_class, $matches[1])); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SmrcD
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   22     3        INIT_FCALL_BY_NAME                                       'change_class'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAL_EX                                              'Bar'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   24     8        INIT_METHOD_CALL                                         !0, 'test'
          9        DO_FCALL                                      0          
   29    10      > RETURN                                                   1

Function change_class:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SmrcD
function name:  change_class
number of ops:  23
compiled vars:  !0 = $object, !1 = $new_class, !2 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%7E%5EO%3A%5B0-9%5D%2B%3A%22%5B%5E%22%5D%2B%22%3A%28.%2B%29%24%7E'
          4        INIT_FCALL                                               'serialize'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        SEND_REF                                                 !2
          9        DO_ICALL                                                 
   28    10        INIT_FCALL                                               'unserialize'
         11        INIT_FCALL                                               'sprintf'
         12        SEND_VAL                                                 'O%3A%25s%3A%22%25s%22%3A%25s'
         13        STRLEN                                           ~5      !1
         14        SEND_VAL                                                 ~5
         15        SEND_VAR                                                 !1
         16        FETCH_DIM_R                                      ~6      !2, 1
         17        SEND_VAL                                                 ~6
         18        DO_ICALL                                         $7      
         19        SEND_VAR                                                 $7
         20        DO_ICALL                                         $8      
         21      > RETURN                                                   $8
   29    22*     > RETURN                                                   null

End of function change_class

Class Foo:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SmrcD
function name:  test
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ECHO                                                     'foo+test'
    8     1      > RETURN                                                   null

End of function test

End of class Foo.

Class Bar:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SmrcD
function name:  test
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ECHO                                                     'bar+test'
   16     1      > RETURN                                                   null

End of function test

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
190.08 ms | 1392 KiB | 21 Q