3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ClassTypeCast(&$obj,$class_type){ if(class_exists($class_type,true)) { $obj = unserialize(preg_replace("/^O:[0-9]+:\"[^\"]+\":/i", "O:".strlen($class_type).":\"".$class_type."\":", serialize($obj))); } } class MyClass { private $foo = null; function setString($str) { $this->foo = $str; } function awful() { return "This is awful!"; } } class MyClass2 { private $foo2 = null; function setString2($str) { $this->foo2 = $str; } function awful() { return "This is awesome!" . PHP_EOL; } } $my1 = new MyClass(); $my1->setString("kill me now"); ClassTypeCast($my1, "MyClass2"); echo $my1->awful() . PHP_EOL; var_dump($my1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TMDfr
function name:  (null)
number of ops:  18
compiled vars:  !0 = $my1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   NEW                                              $1      'MyClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   34     3        INIT_METHOD_CALL                                         !0, 'setString'
          4        SEND_VAL_EX                                              'kill+me+now'
          5        DO_FCALL                                      0          
   36     6        INIT_FCALL                                               'classtypecast'
          7        SEND_REF                                                 !0
          8        SEND_VAL                                                 'MyClass2'
          9        DO_FCALL                                      0          
   37    10        INIT_METHOD_CALL                                         !0, 'awful'
         11        DO_FCALL                                      0  $6      
         12        CONCAT                                           ~7      $6, '%0A'
         13        ECHO                                                     ~7
   39    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function classtypecast:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/TMDfr
function name:  ClassTypeCast
number of ops:  25
compiled vars:  !0 = $obj, !1 = $class_type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'class_exists'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->24
    6     7    >   INIT_FCALL                                               'unserialize'
          8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%2F%5EO%3A%5B0-9%5D%2B%3A%22%5B%5E%22%5D%2B%22%3A%2Fi'
    7    10        STRLEN                                           ~3      !1
         11        CONCAT                                           ~4      'O%3A', ~3
         12        CONCAT                                           ~5      ~4, '%3A%22'
         13        CONCAT                                           ~6      ~5, !1
         14        CONCAT                                           ~7      ~6, '%22%3A'
         15        SEND_VAL                                                 ~7
         16        INIT_FCALL                                               'serialize'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                         $9      
         21        SEND_VAR                                                 $9
         22        DO_ICALL                                         $10     
    6    23        ASSIGN                                                   !0, $10
    9    24    > > RETURN                                                   null

End of function classtypecast

Class MyClass:
Function setstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TMDfr
function name:  setString
number of ops:  4
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN_OBJ                                               'foo'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function setstring

Function awful:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TMDfr
function name:  awful
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E > > RETURN                                                   'This+is+awful%21'
          1*     > RETURN                                                   null

End of function awful

End of class MyClass.

Class MyClass2:
Function setstring2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TMDfr
function name:  setString2
number of ops:  4
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN_OBJ                                               'foo2'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function setstring2

Function awful:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TMDfr
function name:  awful
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E > > RETURN                                                   'This+is+awesome%21%0A'
   30     1*     > RETURN                                                   null

End of function awful

End of class MyClass2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
198.49 ms | 1407 KiB | 24 Q