3v4l.org

run code in 500+ PHP versions simultaneously
<?php class A {} class B {} class C extends A {} $tests = [ 1 => [new A(), new A()], // succeeds 2 => [new A(), new B()], // fails 3 => [new C(), new C()], // succeeds ]; echo 'TEST 1:' . PHP_EOL; foreach ($tests as $index => $collection) { try { array_map(static function (A $object): void {}, $collection); } catch (\TypeError $e) { echo sprintf('Index %d failed, because it doesn\'t contain instances of A only.' . PHP_EOL, $index); } } echo PHP_EOL; echo 'TEST 2:' . PHP_EOL; foreach ($tests as $index => $collection) { try { array_map(static function (C $object): void {}, $collection); } catch (\TypeError $e) { echo sprintf('Index %d failed, because it doesn\'t contain instances of C only.' . PHP_EOL, $index); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 39
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 39
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 58
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 58
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 39
Found catch point at position: 32
Branch analysis from position: 32
2 jumps found. (Code = 107) Position 1 = 33, Position 2 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Found catch point at position: 51
Branch analysis from position: 51
2 jumps found. (Code = 107) Position 1 = 52, Position 2 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
filename:       /in/1IVg9
function name:  (null)
number of ops:  60
compiled vars:  !0 = $tests, !1 = $collection, !2 = $index, !3 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   NEW                                                  $4      'A'
          1        DO_FCALL                                          0          
          2        INIT_ARRAY                                           ~6      $4
          3        NEW                                                  $7      'A'
          4        DO_FCALL                                          0          
          5        ADD_ARRAY_ELEMENT                                    ~6      $7
          6        INIT_ARRAY                                           ~9      ~6, 1
    9     7        NEW                                                  $10     'A'
          8        DO_FCALL                                          0          
          9        INIT_ARRAY                                           ~12     $10
         10        NEW                                                  $13     'B'
         11        DO_FCALL                                          0          
         12        ADD_ARRAY_ELEMENT                                    ~12     $13
         13        ADD_ARRAY_ELEMENT                                    ~9      ~12, 2
   10    14        NEW                                                  $15     'C'
         15        DO_FCALL                                          0          
         16        INIT_ARRAY                                           ~17     $15
         17        NEW                                                  $18     'C'
         18        DO_FCALL                                          0          
         19        ADD_ARRAY_ELEMENT                                    ~17     $18
         20        ADD_ARRAY_ELEMENT                                    ~9      ~17, 3
    7    21        ASSIGN                                                       !0, ~9
   14    22        ECHO                                                         'TEST+1%3A%0A'
   15    23      > FE_RESET_R                                           $21     !0, ->39
         24    > > FE_FETCH_R                                           ~22     $21, !1, ->39
         25    >   ASSIGN                                                       !2, ~22
   17    26        INIT_FCALL                                                   'array_map'
         27        DECLARE_LAMBDA_FUNCTION                              ~24     [0]
         28        SEND_VAL                                                     ~24
         29        SEND_VAR                                                     !1
         30        DO_ICALL                                                     
         31      > JMP                                                          ->38
   18    32  E > > CATCH                                           last         'TypeError'
   19    33    >   ROPE_INIT                                         3  ~28     'Index+'
         34        CAST                                              4  ~26     !2
         35        ROPE_ADD                                          1  ~28     ~28, ~26
         36        ROPE_END                                          2  ~27     ~28, '+failed%2C+because+it+doesn%27t+contain+instances+of+A+only.%0A'
         37        ECHO                                                         ~27
   15    38    > > JMP                                                          ->24
         39    >   FE_FREE                                                      $21
   22    40        ECHO                                                         '%0A'
   24    41        ECHO                                                         'TEST+2%3A%0A'
   25    42      > FE_RESET_R                                           $30     !0, ->58
         43    > > FE_FETCH_R                                           ~31     $30, !1, ->58
         44    >   ASSIGN                                                       !2, ~31
   27    45        INIT_FCALL                                                   'array_map'
         46        DECLARE_LAMBDA_FUNCTION                              ~33     [1]
         47        SEND_VAL                                                     ~33
         48        SEND_VAR                                                     !1
         49        DO_ICALL                                                     
         50      > JMP                                                          ->57
   28    51  E > > CATCH                                           last         'TypeError'
   29    52    >   ROPE_INIT                                         3  ~37     'Index+'
         53        CAST                                              4  ~35     !2
         54        ROPE_ADD                                          1  ~37     ~37, ~35
         55        ROPE_END                                          2  ~36     ~37, '+failed%2C+because+it+doesn%27t+contain+instances+of+C+only.%0A'
         56        ECHO                                                         ~36
   25    57    > > JMP                                                          ->43
         58    >   FE_FREE                                                      $30
   31    59      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IVg9
function name:  {closure:/in/1IVg9:17}
number of ops:  2
compiled vars:  !0 = $object
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IVg9
function name:  {closure:/in/1IVg9:27}
number of ops:  2
compiled vars:  !0 = $object
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of Dynamic Function 1

Class A: [no user functions]
Class B: [no user functions]
Class C: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.16 ms | 2266 KiB | 14 Q