3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Provides dependency injection friendly methods for serialization. */ trait DependencySerializationTrait { /** * An array of service IDs keyed by property name used for serialization. * * @var array */ // phpcs:ignore Drupal.Classes.PropertyDeclaration protected $_serviceIds = []; /** * An array of entity type IDs keyed by the property name of their storages. * * @var array */ // phpcs:ignore Drupal.Classes.PropertyDeclaration protected $_entityStorages = []; /** * {@inheritdoc} */ public function __sleep() { $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() { } } class A { use DependencySerializationTrait; private int $a = 1; 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); } protected function foo() { return $this->a; } } class B extends A { private int $a = 42; private int $b = 2; public function bar() { return $this->foo(); } public function baz() { return $this->a; } } $b = new B(); $b->doit(); echo PHP_EOL; echo "Before serialize:" . PHP_EOL; echo $b->bar() . PHP_EOL; echo $b->baz() . PHP_EOL; $c = unserialize(serialize($b)); echo "After serialize:" . PHP_EOL; echo $c->bar() . PHP_EOL; echo $b->baz() . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  (null)
number of ops:  34
compiled vars:  !0 = $b, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   DECLARE_CLASS                                            'a'
   72     1        DECLARE_CLASS                                            'b', 'a'
   85     2        NEW                                              $2      'B'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   86     5        INIT_METHOD_CALL                                         !0, 'doit'
          6        DO_FCALL                                      0          
   87     7        ECHO                                                     '%0A'
   89     8        ECHO                                                     'Before+serialize%3A%0A'
   90     9        INIT_METHOD_CALL                                         !0, 'bar'
         10        DO_FCALL                                      0  $6      
         11        CONCAT                                           ~7      $6, '%0A'
         12        ECHO                                                     ~7
   91    13        INIT_METHOD_CALL                                         !0, 'baz'
         14        DO_FCALL                                      0  $8      
         15        CONCAT                                           ~9      $8, '%0A'
         16        ECHO                                                     ~9
   94    17        INIT_FCALL                                               'unserialize'
         18        INIT_FCALL                                               'serialize'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                         $11     
         23        ASSIGN                                                   !1, $11
   96    24        ECHO                                                     'After+serialize%3A%0A'
   97    25        INIT_METHOD_CALL                                         !1, 'bar'
         26        DO_FCALL                                      0  $13     
         27        CONCAT                                           ~14     $13, '%0A'
         28        ECHO                                                     ~14
   98    29        INIT_METHOD_CALL                                         !0, 'baz'
         30        DO_FCALL                                      0  $15     
         31        CONCAT                                           ~16     $15, '%0A'
         32        ECHO                                                     ~16
   99    33      > RETURN                                                   1

Class DependencySerializationTrait:
Function __sleep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  __sleep
number of ops:  18
compiled vars:  !0 = $closure, !1 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   30     2        SEND_VAL                                                 ~2
          3        SEND_VAL                                                 null
          4        FETCH_THIS                                       ~3      
          5        SEND_VAL                                                 ~3
   28     6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   32     8        INIT_DYNAMIC_CALL                                        !0
          9        FETCH_THIS                                       $6      
         10        SEND_VAR_EX                                              $6
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !1, $7
   34    13        INIT_FCALL                                               'array_keys'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $9      
         16      > RETURN                                                   $9
   35    17*     > 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/2JvMh
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   30     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/2JvMh
function name:  __wakeup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E > > RETURN                                                   null

End of function __wakeup

End of class DependencySerializationTrait.

Class A:
Function doit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  doIt
number of ops:  26
compiled vars:  !0 = $closure, !1 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   ECHO                                                     'get_object_vars%28%29%0A'
   55     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                                                 
   58     8        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          9        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
   60    10        SEND_VAL                                                 ~5
         11        SEND_VAL                                                 null
         12        FETCH_THIS                                       ~6      
         13        SEND_VAL                                                 ~6
   58    14        DO_FCALL                                      0  $7      
         15        ASSIGN                                                   !0, $7
   62    16        INIT_DYNAMIC_CALL                                        !0
         17        FETCH_THIS                                       $9      
         18        SEND_VAR_EX                                              $9
         19        DO_FCALL                                      0  $10     
         20        ASSIGN                                                   !1, $10
   63    21        ECHO                                                     '%0A%0AClosure%0A'
   64    22        INIT_FCALL                                               'print_r'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
   65    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/2JvMh
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   60     5*     > RETURN                                                   null

End of Dynamic Function 0

End of function doit

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  foo
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   FETCH_OBJ_R                                      ~0      'a'
          1      > RETURN                                                   ~0
   69     2*     > RETURN                                                   null

End of function foo

End of class A.

Class B:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  bar
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   INIT_METHOD_CALL                                         'foo'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   78     3*     > RETURN                                                   null

End of function bar

Function baz:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2JvMh
function name:  baz
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   FETCH_OBJ_R                                      ~0      'a'
          1      > RETURN                                                   ~0
   82     2*     > RETURN                                                   null

End of function baz

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
125.28 ms | 1446 KiB | 18 Q