3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); error_reporting(-1); ini_set('display_errors', 'On'); class Foo { public $id; public function __construct($id) { $this->id = $id; } } $foos = [new Foo(1), new Foo(2), new Foo(3), new Foo(4)]; $fooIds = [1, 2, 3, 4]; $diff = array_udiff($foos, $fooIds, function ($a, $b) { echo gettype($a), ' <=> ', gettype($b), "\n"; if ($a instanceof Foo && $b instanceof Foo) { return $a->id <=> $b->id; } if ($a instanceof Foo) { return $a->id <=> $b; } if ($b instanceof Foo) { return $a <=> $b->id; } return $a <=> $b; }); print_r($diff); // expected result: an empty array
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1uVYf
function name:  (null)
number of ops:  36
compiled vars:  !0 = $foos, !1 = $fooIds, !2 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    5     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 'On'
          6        DO_ICALL                                                 
   16     7        NEW                                              $5      'Foo'
          8        SEND_VAL_EX                                              1
          9        DO_FCALL                                      0          
         10        INIT_ARRAY                                       ~7      $5
         11        NEW                                              $8      'Foo'
         12        SEND_VAL_EX                                              2
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~7      $8
         15        NEW                                              $10     'Foo'
         16        SEND_VAL_EX                                              3
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~7      $10
         19        NEW                                              $12     'Foo'
         20        SEND_VAL_EX                                              4
         21        DO_FCALL                                      0          
         22        ADD_ARRAY_ELEMENT                                ~7      $12
         23        ASSIGN                                                   !0, ~7
   17    24        ASSIGN                                                   !1, <array>
   19    25        INIT_FCALL                                               'array_udiff'
         26        SEND_VAR                                                 !0
         27        SEND_VAR                                                 !1
         28        DECLARE_LAMBDA_FUNCTION                          ~16     [0]
   35    29        SEND_VAL                                                 ~16
   19    30        DO_ICALL                                         $17     
         31        ASSIGN                                                   !2, $17
   37    32        INIT_FCALL                                               'print_r'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                                 
         35      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/1uVYf
function name:  {closure}
number of ops:  30
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        GET_TYPE                                         ~2      !0
          3        ECHO                                                     ~2
          4        ECHO                                                     '+%3C%3D%3E+'
          5        GET_TYPE                                         ~3      !1
          6        ECHO                                                     ~3
          7        ECHO                                                     '%0A'
   22     8        INSTANCEOF                                       ~4      !0, 'Foo'
          9      > JMPZ_EX                                          ~4      ~4, ->12
         10    >   INSTANCEOF                                       ~5      !1, 'Foo'
         11        BOOL                                             ~4      ~5
         12    > > JMPZ                                                     ~4, ->17
   23    13    >   FETCH_OBJ_R                                      ~6      !0, 'id'
         14        FETCH_OBJ_R                                      ~7      !1, 'id'
         15        SPACESHIP                                        ~8      ~6, ~7
         16      > RETURN                                                   ~8
   26    17    >   INSTANCEOF                                               !0, 'Foo'
         18      > JMPZ                                                     ~9, ->22
   27    19    >   FETCH_OBJ_R                                      ~10     !0, 'id'
         20        SPACESHIP                                        ~11     ~10, !1
         21      > RETURN                                                   ~11
   30    22    >   INSTANCEOF                                               !1, 'Foo'
         23      > JMPZ                                                     ~12, ->27
   31    24    >   FETCH_OBJ_R                                      ~13     !1, 'id'
         25        SPACESHIP                                        ~14     !0, ~13
         26      > RETURN                                                   ~14
   34    27    >   SPACESHIP                                        ~15     !0, !1
         28      > RETURN                                                   ~15
   35    29*     > RETURN                                                   null

End of Dynamic Function 0

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1uVYf
function name:  __construct
number of ops:  4
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        ASSIGN_OBJ                                               'id'
          2        OP_DATA                                                  !0
   13     3      > RETURN                                                   null

End of function __construct

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.81 ms | 1019 KiB | 17 Q