3v4l.org

run code in 300+ PHP versions simultaneously
<?php //We set an error handler to throw an ErrorException whenever an error is triggered set_error_handler(function (int $severity, string $message, string $filename, int $line) { echo "Throwing ErrorException\n"; throw new ErrorException($message, 0, $severity, $filename, $line); }); //We're going to test this error handler passing wrong arguments to array_diff //array_diff compares array items CASTING them to string. Yes, it is retarded. No, it's not the lol here. //http://php.net/manual/en/function.array-diff.php //We declare an object that can't be cast to string $stdObject = new stdClass(); //First case: let's trigger an error try { $hello = (string) $stdObject; }catch(ErrorException $ee){ //Handler is called, exception is thrown and catched here. Yay! echo "Catched exception: " . $ee->getMessage() . "\n"; } echo "\n----------\n"; //Second case: let's trigger an error try { array_diff([], [$stdObject]); }catch(ErrorException $ee){ //Handler is called, exception is thrown and catched here. Yay! echo "Catched exception: " . $ee->getMessage() . "\n"; } echo "\n----------\n"; //Third case: let's trigger a slightly different error try { array_diff([$stdObject], [$stdObject]); }catch(ErrorException $ee){ //Handler is called, exception is thrown but... IT IS NOT CATCHED! echo "Catched exception: " . $ee->getMessage() . "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Found catch point at position: 23
Branch analysis from position: 23
2 jumps found. (Code = 107) Position 1 = 24, Position 2 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Found catch point at position: 37
Branch analysis from position: 37
2 jumps found. (Code = 107) Position 1 = 38, Position 2 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pfj29
function name:  (null)
number of ops:  44
compiled vars:  !0 = $stdObject, !1 = $hello, !2 = $ee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'set_error_handler'
          1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPfj29%3A5%240'
    8     2        SEND_VAL                                                 ~3
          3        DO_ICALL                                                 
   15     4        NEW                                              $5      'stdClass'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $5
   19     7        CAST                                          6  ~8      !0
          8        ASSIGN                                                   !1, ~8
          9      > JMP                                                      ->16
   20    10  E > > CATCH                                       last         'ErrorException'
   22    11    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         12        DO_FCALL                                      0  $10     
         13        CONCAT                                           ~11     'Catched+exception%3A+', $10
         14        CONCAT                                           ~12     ~11, '%0A'
         15        ECHO                                                     ~12
   25    16    >   ECHO                                                     '%0A----------%0A'
   29    17        INIT_FCALL                                               'array_diff'
         18        SEND_VAL                                                 <array>
         19        INIT_ARRAY                                       ~13     !0
         20        SEND_VAL                                                 ~13
         21        DO_ICALL                                                 
         22      > JMP                                                      ->29
   30    23  E > > CATCH                                       last         'ErrorException'
   32    24    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         25        DO_FCALL                                      0  $15     
         26        CONCAT                                           ~16     'Catched+exception%3A+', $15
         27        CONCAT                                           ~17     ~16, '%0A'
         28        ECHO                                                     ~17
   35    29    >   ECHO                                                     '%0A----------%0A'
   39    30        INIT_FCALL                                               'array_diff'
         31        INIT_ARRAY                                       ~18     !0
         32        SEND_VAL                                                 ~18
         33        INIT_ARRAY                                       ~19     !0
         34        SEND_VAL                                                 ~19
         35        DO_ICALL                                                 
         36      > JMP                                                      ->43
   40    37  E > > CATCH                                       last         'ErrorException'
   42    38    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         39        DO_FCALL                                      0  $21     
         40        CONCAT                                           ~22     'Catched+exception%3A+', $21
         41        CONCAT                                           ~23     ~22, '%0A'
         42        ECHO                                                     ~23
   43    43    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FPfj29%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/Pfj29
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $severity, !1 = $message, !2 = $filename, !3 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    6     4        ECHO                                                     'Throwing+ErrorException%0A'
    7     5        NEW                                              $4      'ErrorException'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAL_EX                                              0
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !2
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $4
    8    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPfj29%3A5%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.49 ms | 1400 KiB | 17 Q