3v4l.org

run code in 300+ PHP versions simultaneously
<?php function object_diff($source, $target) { if (!is_object($source) || !is_object($target) || !($source instanceof $target)) { return null; } $sourceReflection = new ReflectionObject($source); $targetReflection = new ReflectionObject($target); $sourceProperties = array_map(function (ReflectionProperty $property) use ($source) { $property->setAccessible(true); return $property->getValue($source); }, $sourceReflection->getProperties()); $targetProperties = array_map(function (ReflectionProperty $property) use ($target) { $property->setAccessible(true); return $property->getValue($target); }, $targetReflection->getProperties()); return array_diff($sourceProperties, $targetProperties); } class Foo { private $a, $b, $c; public function __construct($a, $b, $c) { $this->a = $a; $this->c = $b; $this->b = $b; } } $foo1 = new Foo('a', 'b', 'c'); $foo2 = new Foo('a', 'b', 'd'); var_dump(object_diff($foo1, $foo2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TeC96
function name:  (null)
number of ops:  20
compiled vars:  !0 = $foo1, !1 = $foo2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $2      'Foo'
          1        SEND_VAL_EX                                              'a'
          2        SEND_VAL_EX                                              'b'
          3        SEND_VAL_EX                                              'c'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   37     6        NEW                                              $5      'Foo'
          7        SEND_VAL_EX                                              'a'
          8        SEND_VAL_EX                                              'b'
          9        SEND_VAL_EX                                              'd'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $5
   40    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'object_diff'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function object_diff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/TeC96
function name:  object_diff
number of ops:  47
compiled vars:  !0 = $source, !1 = $target, !2 = $sourceReflection, !3 = $targetReflection, !4 = $sourceProperties, !5 = $targetProperties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        TYPE_CHECK                                  256  ~6      !0
          3        BOOL_NOT                                         ~7      ~6
          4      > JMPNZ_EX                                         ~7      ~7, ->8
          5    >   TYPE_CHECK                                  256  ~8      !1
          6        BOOL_NOT                                         ~9      ~8
          7        BOOL                                             ~7      ~9
          8    > > JMPNZ_EX                                         ~7      ~7, ->13
          9    >   FETCH_CLASS                                   0  $10     !1
         10        INSTANCEOF                                       ~11     !0, $10
         11        BOOL_NOT                                         ~12     ~11
         12        BOOL                                             ~7      ~12
         13    > > JMPZ                                                     ~7, ->15
    7    14    > > RETURN                                                   null
    9    15    >   NEW                                              $13     'ReflectionObject'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $13
   10    19        NEW                                              $16     'ReflectionObject'
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !3, $16
   11    23        INIT_FCALL                                               'array_map'
         24        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTeC96%3A11%240'
         25        BIND_LEXICAL                                             ~19, !0
   14    26        SEND_VAL                                                 ~19
         27        INIT_METHOD_CALL                                         !2, 'getProperties'
         28        DO_FCALL                                      0  $20     
         29        SEND_VAR                                                 $20
         30        DO_ICALL                                         $21     
   11    31        ASSIGN                                                   !4, $21
   15    32        INIT_FCALL                                               'array_map'
         33        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTeC96%3A15%241'
         34        BIND_LEXICAL                                             ~23, !1
   18    35        SEND_VAL                                                 ~23
         36        INIT_METHOD_CALL                                         !3, 'getProperties'
         37        DO_FCALL                                      0  $24     
         38        SEND_VAR                                                 $24
         39        DO_ICALL                                         $25     
   15    40        ASSIGN                                                   !5, $25
   19    41        INIT_FCALL                                               'array_diff'
         42        SEND_VAR                                                 !4
         43        SEND_VAR                                                 !5
         44        DO_ICALL                                         $27     
         45      > RETURN                                                   $27
   20    46*     > RETURN                                                   null

End of function object_diff

Function %00%7Bclosure%7D%2Fin%2FTeC96%3A11%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TeC96
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $property, !1 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   12     2        INIT_METHOD_CALL                                         !0, 'setAccessible'
          3        SEND_VAL_EX                                              <true>
          4        DO_FCALL                                      0          
   13     5        INIT_METHOD_CALL                                         !0, 'getValue'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   14     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTeC96%3A11%240

Function %00%7Bclosure%7D%2Fin%2FTeC96%3A15%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TeC96
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $property, !1 = $target
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   16     2        INIT_METHOD_CALL                                         !0, 'setAccessible'
          3        SEND_VAL_EX                                              <true>
          4        DO_FCALL                                      0          
   17     5        INIT_METHOD_CALL                                         !0, 'getValue'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   18     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTeC96%3A15%241

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TeC96
function name:  __construct
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   29     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
   30     5        ASSIGN_OBJ                                               'c'
          6        OP_DATA                                                  !1
   31     7        ASSIGN_OBJ                                               'b'
          8        OP_DATA                                                  !1
   32     9      > RETURN                                                   null

End of function __construct

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.63 ms | 1407 KiB | 20 Q