3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Provides dependency injection friendly methods for serialization. */ trait DependencySerializationTrait { /** * {@inheritdoc} */ public function __sleep() { echo "hydrating " . $this::class . PHP_EOL; $closure = \Closure::bind(static function ($class) { return get_object_vars($class); }, NULL, $this); $vars = $closure($this); return array_keys($vars); } /** * {@inheritdoc} */ #[\ReturnTypeWillChange] public function __wakeup() { echo "dehydrating " . $this::class . PHP_EOL; } } trait dumper { public function doIt() { print "get_object_vars()\n"; print_r(get_object_vars($this)); $closure = \Closure::bind(static function ($class) { return get_object_vars($class); }, NULL, $this); $vars = $closure($this); print "\n\nClosure\n"; print_r($vars); } } class A { use dumper; use DependencySerializationTrait; private int $a = 1; public function echoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } class B extends A { } class C extends B { use dumper; private int $a = 2; public function scopeCechoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } class D extends B { use DependencySerializationTrait; private int $a = 3; public function scopeDechoA() { echo $this::class . "::" . __METHOD__ . ":" . $this->a . PHP_EOL; } } print "Class A\n"; (new A())->doit(); print "\n\nClass B\n"; $b = new B(); ($b)->doit(); print "\n\nClass C\n"; $c = new C(); ($c)->doit(); print "\n\nClass D\n"; $d = new D(); ($d)->doit(); echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before B got serialized/deserialized:" . PHP_EOL; $b->echoA(); $b2 = unserialize(serialize($b)); echo "After B got serialized/deserialized:" . PHP_EOL; $b2->echoA(); echo "<<<<<<<<" . PHP_EOL; echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before C got serialized/deserialized:" . PHP_EOL; $c->echoA(); $c->scopeCechoA(); $c2 = unserialize(serialize($c)); echo "After C got serialized/deserialized:" . PHP_EOL; $c2->echoA(); $c2->scopeCechoA(); echo "<<<<<<<<" . PHP_EOL; echo PHP_EOL . PHP_EOL; echo ">>>>>>>>" . PHP_EOL; echo "Before D got serialized/deserialized:" . PHP_EOL; $d->echoA(); $d->scopeDechoA(); $d2 = unserialize(serialize($d)); echo "After D got serialized/deserialized:" . PHP_EOL; $d2->echoA(); $d2->scopeDechoA(); echo "<<<<<<<<" . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  (null)
number of ops:  84
compiled vars:  !0 = $b, !1 = $c, !2 = $d, !3 = $b2, !4 = $c2, !5 = $d2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   DECLARE_CLASS                                            'a'
   60     1        DECLARE_CLASS                                            'b', 'a'
   63     2        DECLARE_CLASS                                            'c', 'b'
   74     3        DECLARE_CLASS                                            'd', 'b'
   85     4        ECHO                                                     'Class+A%0A'
   86     5        NEW                                              $6      'A'
          6        DO_FCALL                                      0          
          7        INIT_METHOD_CALL                                         $6, 'doit'
          8        DO_FCALL                                      0          
   88     9        ECHO                                                     '%0A%0AClass+B%0A'
   89    10        NEW                                              $9      'B'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !0, $9
   90    13        INIT_METHOD_CALL                                         !0, 'doit'
         14        DO_FCALL                                      0          
   91    15        ECHO                                                     '%0A%0AClass+C%0A'
   92    16        NEW                                              $13     'C'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !1, $13
   93    19        INIT_METHOD_CALL                                         !1, 'doit'
         20        DO_FCALL                                      0          
   94    21        ECHO                                                     '%0A%0AClass+D%0A'
   95    22        NEW                                              $17     'D'
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !2, $17
   96    25        INIT_METHOD_CALL                                         !2, 'doit'
         26        DO_FCALL                                      0          
   98    27        ECHO                                                     '%0A%0A'
  100    28        ECHO                                                     '%3E%3E%3E%3E%3E%3E%3E%3E%0A'
  102    29        ECHO                                                     'Before+B+got+serialized%2Fdeserialized%3A%0A'
  103    30        INIT_METHOD_CALL                                         !0, 'echoA'
         31        DO_FCALL                                      0          
  106    32        INIT_FCALL                                               'unserialize'
         33        INIT_FCALL                                               'serialize'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $22     
         36        SEND_VAR                                                 $22
         37        DO_ICALL                                         $23     
         38        ASSIGN                                                   !3, $23
  107    39        ECHO                                                     'After+B+got+serialized%2Fdeserialized%3A%0A'
  108    40        INIT_METHOD_CALL                                         !3, 'echoA'
         41        DO_FCALL                                      0          
  110    42        ECHO                                                     '%3C%3C%3C%3C%3C%3C%3C%3C%0A'
  112    43        ECHO                                                     '%0A%0A'
  114    44        ECHO                                                     '%3E%3E%3E%3E%3E%3E%3E%3E%0A'
  116    45        ECHO                                                     'Before+C+got+serialized%2Fdeserialized%3A%0A'
  117    46        INIT_METHOD_CALL                                         !1, 'echoA'
         47        DO_FCALL                                      0          
  118    48        INIT_METHOD_CALL                                         !1, 'scopeCechoA'
         49        DO_FCALL                                      0          
  121    50        INIT_FCALL                                               'unserialize'
         51        INIT_FCALL                                               'serialize'
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $28     
         54        SEND_VAR                                                 $28
         55        DO_ICALL                                         $29     
         56        ASSIGN                                                   !4, $29
  122    57        ECHO                                                     'After+C+got+serialized%2Fdeserialized%3A%0A'
  123    58        INIT_METHOD_CALL                                         !4, 'echoA'
         59        DO_FCALL                                      0          
  124    60        INIT_METHOD_CALL                                         !4, 'scopeCechoA'
         61        DO_FCALL                                      0          
  127    62        ECHO                                                     '%3C%3C%3C%3C%3C%3C%3C%3C%0A'
  129    63        ECHO                                                     '%0A%0A'
  131    64        ECHO                                                     '%3E%3E%3E%3E%3E%3E%3E%3E%0A'
  133    65        ECHO                                                     'Before+D+got+serialized%2Fdeserialized%3A%0A'
  134    66        INIT_METHOD_CALL                                         !2, 'echoA'
         67        DO_FCALL                                      0          
  135    68        INIT_METHOD_CALL                                         !2, 'scopeDechoA'
         69        DO_FCALL                                      0          
  138    70        INIT_FCALL                                               'unserialize'
         71        INIT_FCALL                                               'serialize'
         72        SEND_VAR                                                 !2
         73        DO_ICALL                                         $35     
         74        SEND_VAR                                                 $35
         75        DO_ICALL                                         $36     
         76        ASSIGN                                                   !5, $36
  139    77        ECHO                                                     'After+D+got+serialized%2Fdeserialized%3A%0A'
  140    78        INIT_METHOD_CALL                                         !5, 'echoA'
         79        DO_FCALL                                      0          
  141    80        INIT_METHOD_CALL                                         !5, 'scopeDechoA'
         81        DO_FCALL                                      0          
  143    82        ECHO                                                     '%3C%3C%3C%3C%3C%3C%3C%3C%0A'
  144    83      > RETURN                                                   1

Class DependencySerializationTrait:
Function __sleep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  __sleep
number of ops:  23
compiled vars:  !0 = $closure, !1 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_THIS                                       ~2      
          1        FETCH_CLASS_NAME                                 ~3      ~2
          2        CONCAT                                           ~4      'hydrating+', ~3
          3        CONCAT                                           ~5      ~4, '%0A'
          4        ECHO                                                     ~5
   14     5        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          6        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   16     7        SEND_VAL                                                 ~6
          8        SEND_VAL                                                 null
          9        FETCH_THIS                                       ~7      
         10        SEND_VAL                                                 ~7
   14    11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !0, $8
   18    13        INIT_DYNAMIC_CALL                                        !0
         14        FETCH_THIS                                       $10     
         15        SEND_VAR_EX                                              $10
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !1, $11
   20    18        INIT_FCALL                                               'array_keys'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $13     
         21      > RETURN                                                   $13
   21    22*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   16     5*     > RETURN                                                   null

End of Dynamic Function 0

End of function __sleep

Function __wakeup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  __wakeup
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_THIS                                       ~0      
          1        FETCH_CLASS_NAME                                 ~1      ~0
          2        CONCAT                                           ~2      'dehydrating+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
   29     5      > RETURN                                                   null

End of function __wakeup

End of class DependencySerializationTrait.

Class dumper:
Function doit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  doIt
number of ops:  26
compiled vars:  !0 = $closure, !1 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ECHO                                                     'get_object_vars%28%29%0A'
   36     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'get_object_vars'
          3        FETCH_THIS                                       ~2      
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   39     8        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          9        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
   41    10        SEND_VAL                                                 ~5
         11        SEND_VAL                                                 null
         12        FETCH_THIS                                       ~6      
         13        SEND_VAL                                                 ~6
   39    14        DO_FCALL                                      0  $7      
         15        ASSIGN                                                   !0, $7
   43    16        INIT_DYNAMIC_CALL                                        !0
         17        FETCH_THIS                                       $9      
         18        SEND_VAR_EX                                              $9
         19        DO_FCALL                                      0  $10     
         20        ASSIGN                                                   !1, $10
   44    21        ECHO                                                     '%0A%0AClosure%0A'
   45    22        INIT_FCALL                                               'print_r'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
   46    25      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   41     5*     > RETURN                                                   null

End of Dynamic Function 0

End of function doit

End of class dumper.

Class A:
Function echoa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  echoA
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_THIS                                       ~0      
          1        FETCH_CLASS_NAME                                 ~1      ~0
          2        CONCAT                                           ~2      ~1, '%3A%3A'
          3        CONCAT                                           ~3      ~2, 'A%3A%3AechoA'
          4        CONCAT                                           ~4      ~3, '%3A'
          5        FETCH_OBJ_R                                      ~5      'a'
          6        CONCAT                                           ~6      ~4, ~5
          7        CONCAT                                           ~7      ~6, '%0A'
          8        ECHO                                                     ~7
   57     9      > RETURN                                                   null

End of function echoa

End of class A.

Class B: [no user functions]
Class C:
Function scopecechoa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  scopeCechoA
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   FETCH_THIS                                       ~0      
          1        FETCH_CLASS_NAME                                 ~1      ~0
          2        CONCAT                                           ~2      ~1, '%3A%3A'
          3        CONCAT                                           ~3      ~2, 'C%3A%3AscopeCechoA'
          4        CONCAT                                           ~4      ~3, '%3A'
          5        FETCH_OBJ_R                                      ~5      'a'
          6        CONCAT                                           ~6      ~4, ~5
          7        CONCAT                                           ~7      ~6, '%0A'
          8        ECHO                                                     ~7
   70     9      > RETURN                                                   null

End of function scopecechoa

End of class C.

Class D:
Function scopedechoa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfrhp
function name:  scopeDechoA
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   FETCH_THIS                                       ~0      
          1        FETCH_CLASS_NAME                                 ~1      ~0
          2        CONCAT                                           ~2      ~1, '%3A%3A'
          3        CONCAT                                           ~3      ~2, 'D%3A%3AscopeDechoA'
          4        CONCAT                                           ~4      ~3, '%3A'
          5        FETCH_OBJ_R                                      ~5      'a'
          6        CONCAT                                           ~6      ~4, ~5
          7        CONCAT                                           ~7      ~6, '%0A'
          8        ECHO                                                     ~7
   81     9      > RETURN                                                   null

End of function scopedechoa

End of class D.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.8 ms | 1480 KiB | 18 Q