3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $prot; public $pub; } 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; } //hydrate('Foo'); var_dump( hydrate('Foo',array('prot'=>1,'pub'=>2)) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9XQZX
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'var_dump'
   37     1        INIT_FCALL                                               'hydrate'
          2        SEND_VAL                                                 'Foo'
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   38     7      > RETURN                                                   1

Function dehydrate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9XQZX
function name:  dehydrate
number of ops:  23
compiled vars:  !0 = $obj, !1 = $class, !2 = $exp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        GET_CLASS                                        ~3      !0
          2        ASSIGN                                                   !1, ~3
   11     3        INIT_FCALL                                               'var_export'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   12     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
   13    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/9XQZX
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
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   16     2        BIND_STATIC                                              !2
   17     3        CONCAT                                           ~4      '_Hydrator__', !0
          4        ASSIGN                                                   !3, ~4
   18     5        ISSET_ISEMPTY_DIM_OBJ                         1          !2, !0
          6      > JMPZ                                                     ~6, ->16
   19     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+'
   21    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
   27    14        ASSIGN_DIM                                               !2, !0
         15        OP_DATA                                                  <true>
   29    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
   30    25*     > RETURN                                                   null

End of function hydrate

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.67 ms | 1403 KiB | 22 Q