3v4l.org

run code in 300+ PHP versions simultaneously
<?php function e($o){return json_decode(preg_replace('/\\\u0000[*a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\\\u0000/','',json_encode((array)$o)),1);} function cast($destination, $sourceObject) { if (is_string($destination)) { $destination = new $destination(); } $sourceReflection = new ReflectionObject($sourceObject); $destinationReflection = new ReflectionObject($destination); $sourceProperties = $sourceReflection->getProperties(); foreach ($sourceProperties as $sourceProperty) { $sourceProperty->setAccessible(true); $name = $sourceProperty->getName(); $value = $sourceProperty->getValue($sourceObject); if ($destinationReflection->hasProperty($name)) { $propDest = $destinationReflection->getProperty($name); $propDest->setAccessible(true); $propDest->setValue($destination,$value); } else { $destination->$name = $value; } } return $destination; } class Foo { public function test() { echo 'test'; } } function changeMe(&$obj) { $sourceClass = get_class($obj); $obj = function(){ echo 'hello'; }; //$reflectionClass = new ReflectionClass($obj); //var_dump($reflectionClass); $arr = (array) $obj; $obj = (object) $arr; $obj = cast($obj, $sourceClass); var_dump($arr, $obj); //$out = json_encode($arr); //$out = preg_replace('/\\\u0000[*a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\\\u0000/', '', $out); //echo $out . PHP_EOL; //$newArray = json_decode($out, true); //var_dump($arr, $newArray); } $foo = new Foo(); changeMe($foo); $foo->test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mLKpg
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   63     3        INIT_FCALL                                               'changeme'
          4        SEND_REF                                                 !0
          5        DO_FCALL                                      0          
   65     6        INIT_METHOD_CALL                                         !0, 'test'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function e:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mLKpg
function name:  e
number of ops:  16
compiled vars:  !0 = $o
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5C%5Cu0000%5B%2Aa-zA-Z_%5Cx7f-%5Cxff%5D%5Ba-zA-Z0-9_%5Cx7f-%5Cxff%5D%2A%5C%5Cu0000%2F'
          4        SEND_VAL                                                 ''
          5        INIT_FCALL                                               'json_encode'
          6        CAST                                          7  ~1      !0
          7        SEND_VAL                                                 ~1
          8        DO_ICALL                                         $2      
          9        SEND_VAR                                                 $2
         10        DO_ICALL                                         $3      
         11        SEND_VAR                                                 $3
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $4      
         14      > RETURN                                                   $4
         15*     > RETURN                                                   null

End of function e

Function cast:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 50
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 50
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 8
filename:       /in/mLKpg
function name:  cast
number of ops:  53
compiled vars:  !0 = $destination, !1 = $sourceObject, !2 = $sourceReflection, !3 = $destinationReflection, !4 = $sourceProperties, !5 = $sourceProperty, !6 = $name, !7 = $value, !8 = $propDest
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        TYPE_CHECK                                   64          !0
          3      > JMPZ                                                     ~9, ->8
   10     4    >   FETCH_CLASS                                   0  $10     !0
          5        NEW                                              $11     $10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $11
   12     8    >   NEW                                              $14     'ReflectionObject'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $14
   13    12        NEW                                              $17     'ReflectionObject'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $17
   14    16        INIT_METHOD_CALL                                         !2, 'getProperties'
         17        DO_FCALL                                      0  $20     
         18        ASSIGN                                                   !4, $20
   15    19      > FE_RESET_R                                       $22     !4, ->50
         20    > > FE_FETCH_R                                               $22, !5, ->50
   16    21    >   INIT_METHOD_CALL                                         !5, 'setAccessible'
         22        SEND_VAL_EX                                              <true>
         23        DO_FCALL                                      0          
   17    24        INIT_METHOD_CALL                                         !5, 'getName'
         25        DO_FCALL                                      0  $24     
         26        ASSIGN                                                   !6, $24
   18    27        INIT_METHOD_CALL                                         !5, 'getValue'
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0  $26     
         30        ASSIGN                                                   !7, $26
   19    31        INIT_METHOD_CALL                                         !3, 'hasProperty'
         32        SEND_VAR_EX                                              !6
         33        DO_FCALL                                      0  $28     
         34      > JMPZ                                                     $28, ->47
   20    35    >   INIT_METHOD_CALL                                         !3, 'getProperty'
         36        SEND_VAR_EX                                              !6
         37        DO_FCALL                                      0  $29     
         38        ASSIGN                                                   !8, $29
   21    39        INIT_METHOD_CALL                                         !8, 'setAccessible'
         40        SEND_VAL_EX                                              <true>
         41        DO_FCALL                                      0          
   22    42        INIT_METHOD_CALL                                         !8, 'setValue'
         43        SEND_VAR_EX                                              !0
         44        SEND_VAR_EX                                              !7
         45        DO_FCALL                                      0          
         46      > JMP                                                      ->49
   24    47    >   ASSIGN_OBJ                                               !0, !6
         48        OP_DATA                                                  !7
   15    49    > > JMP                                                      ->20
         50    >   FE_FREE                                                  $22
   27    51      > RETURN                                                   !0
   28    52*     > RETURN                                                   null

End of function cast

Function changeme:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mLKpg
function name:  changeMe
number of ops:  19
compiled vars:  !0 = $obj, !1 = $sourceClass, !2 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        GET_CLASS                                        ~3      !0
          2        ASSIGN                                                   !1, ~3
   42     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmLKpg%3A42%240'
          4        ASSIGN                                                   !0, ~5
   47     5        CAST                                          7  ~7      !0
          6        ASSIGN                                                   !2, ~7
   49     7        CAST                                          8  ~9      !2
          8        ASSIGN                                                   !0, ~9
   50     9        INIT_FCALL                                               'cast'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !0, $11
   51    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !2
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
   59    18      > RETURN                                                   null

End of function changeme

Function %00%7Bclosure%7D%2Fin%2FmLKpg%3A42%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mLKpg
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ECHO                                                     'hello'
   44     1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmLKpg%3A42%240

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

End of function test

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.1 ms | 1407 KiB | 23 Q