3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $prot; public $pub; public function init(){ $this->prot = rand(1,9); $this->pub = rand(1,9); } } function dehydrate($obj){ $class = get_class($obj); $exp = var_export($obj,1); return eval('return '.substr($exp,strpos($exp,'(')+1,-1).';'); } function hydrate($class,$dry=null){ static $hydrators = array(); $h = '_Hydrator__'.$class; if (empty($hydrators[$class])) { eval('class '.$h.' extends '.$class.' { static function __hydrate(array $array) { $o = new '.$class.'(); foreach ($array as $prop_name => $prop_value) $o->$prop_name = $prop_value; return $o; } } '); $hydrators[$class] = true; } return $dry?$h::__hydrate($dry):null; } $a = new Foo(); $a->init(); $dry = dehydrate($a); hydrate('Foo'); var_dump( hydrate('Foo',$dry) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbbjH
function name:  (null)
number of ops:  20
compiled vars:  !0 = $a, !1 = $dry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   NEW                                              $2      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   39     3        INIT_METHOD_CALL                                         !0, 'init'
          4        DO_FCALL                                      0          
   40     5        INIT_FCALL                                               'dehydrate'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !1, $6
   41     9        INIT_FCALL                                               'hydrate'
         10        SEND_VAL                                                 'Foo'
         11        DO_FCALL                                      0          
   43    12        INIT_FCALL                                               'var_dump'
   44    13        INIT_FCALL                                               'hydrate'
         14        SEND_VAL                                                 'Foo'
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR                                                 $9
         18        DO_ICALL                                                 
   45    19      > RETURN                                                   1

Function dehydrate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbbjH
function name:  dehydrate
number of ops:  23
compiled vars:  !0 = $obj, !1 = $class, !2 = $exp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        GET_CLASS                                        ~3      !0
          2        ASSIGN                                                   !1, ~3
   16     3        INIT_FCALL                                               'var_export'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   17     8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !2
         10        INIT_FCALL                                               'strpos'
         11        SEND_VAR                                                 !2
         12        SEND_VAL                                                 '%28'
         13        DO_ICALL                                         $7      
         14        ADD                                              ~8      $7, 1
         15        SEND_VAL                                                 ~8
         16        SEND_VAL                                                 -1
         17        DO_ICALL                                         $9      
         18        CONCAT                                           ~10     'return+', $9
         19        CONCAT                                           ~11     ~10, '%3B'
         20        INCLUDE_OR_EVAL                                  $12     ~11, EVAL
         21      > RETURN                                                   $12
   18    22*     > RETURN                                                   null

End of function dehydrate

Function hydrate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/qbbjH
function name:  hydrate
number of ops:  26
compiled vars:  !0 = $class, !1 = $dry, !2 = $hydrators, !3 = $h
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   21     2        BIND_STATIC                                              !2
   22     3        CONCAT                                           ~4      '_Hydrator__', !0
          4        ASSIGN                                                   !3, ~4
   23     5        ISSET_ISEMPTY_DIM_OBJ                         1          !2, !0
          6      > JMPZ                                                     ~6, ->16
   24     7    >   CONCAT                                           ~7      'class+', !3
          8        CONCAT                                           ~8      ~7, '+extends+'
          9        CONCAT                                           ~9      ~8, !0
         10        CONCAT                                           ~10     ~9, '+%7B%0A++++++++++++++++++static+function+__hydrate%28array+%24array%29+%7B%0A++++++++++++++++++++++%24o+%3D+new+'
   26    11        CONCAT                                           ~11     ~10, !0
         12        CONCAT                                           ~12     ~11, '%28%29%3B%0A++++++++++++++++++++++foreach+%28%24array+as+%24prop_name+%3D%3E+%24prop_value%29+%24o-%3E%24prop_name+%3D+%24prop_value%3B%0A++++++++++++++++++++++return+%24o%3B%0A++++++++++++++++++%7D+++%0A++++++++++++++%7D%0A++++++++'
         13        INCLUDE_OR_EVAL                                          ~12, EVAL
   32    14        ASSIGN_DIM                                               !2, !0
         15        OP_DATA                                                  <true>
   34    16    > > JMPZ                                                     !1, ->23
         17    >   FETCH_CLASS                                   0  $15     !3
         18        INIT_STATIC_METHOD_CALL                                  $15, '__hydrate'
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $16     
         21        QM_ASSIGN                                        ~17     $16
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~17     null
         24    > > RETURN                                                   ~17
   35    25*     > RETURN                                                   null

End of function hydrate

Class Foo:
Function init:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbbjH
function name:  init
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 9
          3        DO_ICALL                                         $1      
          4        ASSIGN_OBJ                                               'prot'
          5        OP_DATA                                                  $1
    9     6        INIT_FCALL                                               'rand'
          7        SEND_VAL                                                 1
          8        SEND_VAL                                                 9
          9        DO_ICALL                                         $3      
         10        ASSIGN_OBJ                                               'pub'
         11        OP_DATA                                                  $3
   10    12      > RETURN                                                   null

End of function init

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.56 ms | 1411 KiB | 26 Q