3v4l.org

run code in 300+ PHP versions simultaneously
<?php // error handler function function myErrorHandler($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting return; } switch ($errno) { case E_USER_ERROR: echo "<b>My ERROR</b> [$errno] $errstr<br />\n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; exit(1); break; case E_USER_WARNING: echo "<b>My WARNING</b> [$errno] $errstr<br />\n"; break; case E_USER_NOTICE: echo "<b>My NOTICE</b> [$errno] $errstr<br />\n"; break; default: echo "Unknown error type: [$errno] $errstr<br />\n"; break; } /* Don't execute PHP internal error handler */ return true; } // function to test the error handling function scale_by_log($vect, $scale) { if (!is_numeric($scale) || $scale <= 0) { trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR); } if (!is_array($vect)) { trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING); return null; } $temp = array(); foreach($vect as $pos => $value) { if (!is_numeric($value)) { trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE); $value = 0; } $temp[$pos] = log($scale) * $value; } return $temp; } // set to the user defined error handler $old_error_handler = set_error_handler("myErrorHandler"); // trigger some errors, first define a mixed array with a non-numeric item echo "vector a\n"; $a = array(2, 3, "foo", 5.5, 43.3, 21.11); print_r($a); // now generate second array echo "----\nvector b - a notice (b = log(PI) * a)\n"; /* Value at position $pos is not a number, using 0 (zero) */ $b = scale_by_log($a, M_PI); print_r($b); // this is trouble, we pass a string instead of an array echo "----\nvector c - a warning\n"; /* Incorrect input vector, array of values expected */ $c = scale_by_log("not array", 2.3); var_dump($c); // NULL // this is a critical error, log of zero or negative number is undefined echo "----\nvector d - fatal error\n"; /* log(x) for x <= 0 is undefined, you used: scale = $scale" */ $d = scale_by_log($a, -2.5); var_dump($d); // Never reached
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/36iFH
function name:  (null)
number of ops:  37
compiled vars:  !0 = $old_error_handler, !1 = $a, !2 = $b, !3 = $c, !4 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'set_error_handler'
          1        SEND_VAL                                                 'myErrorHandler'
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
   64     4        ECHO                                                     'vector+a%0A'
   65     5        ASSIGN                                                   !1, <array>
   66     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   69     9        ECHO                                                     '----%0Avector+b+-+a+notice+%28b+%3D+log%28PI%29+%2A+a%29%0A'
   71    10        INIT_FCALL                                               'scale_by_log'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 3.14159
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !2, $9
   72    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                                 
   75    18        ECHO                                                     '----%0Avector+c+-+a+warning%0A'
   77    19        INIT_FCALL                                               'scale_by_log'
         20        SEND_VAL                                                 'not+array'
         21        SEND_VAL                                                 2.3
         22        DO_FCALL                                      0  $12     
         23        ASSIGN                                                   !3, $12
   78    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                                 
   81    27        ECHO                                                     '----%0Avector+d+-+fatal+error%0A'
   83    28        INIT_FCALL                                               'scale_by_log'
         29        SEND_VAR                                                 !1
         30        SEND_VAL                                                 -2.5
         31        DO_FCALL                                      0  $15     
         32        ASSIGN                                                   !4, $15
   84    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Function myerrorhandler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 32
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 39
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 17
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/36iFH
function name:  myErrorHandler
number of ops:  55
compiled vars:  !0 = $errno, !1 = $errstr, !2 = $errfile, !3 = $errline
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    5     4        INIT_FCALL                                               'error_reporting'
          5        DO_ICALL                                         $4      
          6        BW_AND                                           ~5      !0, $4
          7        BOOL_NOT                                         ~6      ~5
          8      > JMPZ                                                     ~6, ->10
    7     9    > > RETURN                                                   null
   10    10    >   IS_EQUAL                                                 !0, 256
         11      > JMPNZ                                                    ~7, ->17
         12    >   IS_EQUAL                                                 !0, 512
         13      > JMPNZ                                                    ~7, ->32
         14    >   IS_EQUAL                                                 !0, 1024
         15      > JMPNZ                                                    ~7, ->39
         16    > > JMP                                                      ->46
   12    17    >   ROPE_INIT                                     5  ~9      '%3Cb%3EMy+ERROR%3C%2Fb%3E+%5B'
         18        ROPE_ADD                                      1  ~9      ~9, !0
         19        ROPE_ADD                                      2  ~9      ~9, '%5D+'
         20        ROPE_ADD                                      3  ~9      ~9, !1
         21        ROPE_END                                      4  ~8      ~9, '%3Cbr+%2F%3E%0A'
         22        ECHO                                                     ~8
   13    23        ROPE_INIT                                     4  ~13     '++Fatal+error+on+line+'
         24        ROPE_ADD                                      1  ~13     ~13, !3
         25        ROPE_ADD                                      2  ~13     ~13, '+in+file+'
         26        ROPE_END                                      3  ~12     ~13, !2
         27        ECHO                                                     ~12
   14    28        ECHO                                                     '%2C+PHP+8.0.0+%28Linux%29%3Cbr+%2F%3E%0A'
   15    29        ECHO                                                     'Aborting...%3Cbr+%2F%3E%0A'
   16    30      > EXIT                                                     1
   17    31*       JMP                                                      ->53
   20    32    >   ROPE_INIT                                     5  ~16     '%3Cb%3EMy+WARNING%3C%2Fb%3E+%5B'
         33        ROPE_ADD                                      1  ~16     ~16, !0
         34        ROPE_ADD                                      2  ~16     ~16, '%5D+'
         35        ROPE_ADD                                      3  ~16     ~16, !1
         36        ROPE_END                                      4  ~15     ~16, '%3Cbr+%2F%3E%0A'
         37        ECHO                                                     ~15
   21    38      > JMP                                                      ->53
   24    39    >   ROPE_INIT                                     5  ~20     '%3Cb%3EMy+NOTICE%3C%2Fb%3E+%5B'
         40        ROPE_ADD                                      1  ~20     ~20, !0
         41        ROPE_ADD                                      2  ~20     ~20, '%5D+'
         42        ROPE_ADD                                      3  ~20     ~20, !1
         43        ROPE_END                                      4  ~19     ~20, '%3Cbr+%2F%3E%0A'
         44        ECHO                                                     ~19
   25    45      > JMP                                                      ->53
   28    46    >   ROPE_INIT                                     5  ~24     'Unknown+error+type%3A+%5B'
         47        ROPE_ADD                                      1  ~24     ~24, !0
         48        ROPE_ADD                                      2  ~24     ~24, '%5D+'
         49        ROPE_ADD                                      3  ~24     ~24, !1
         50        ROPE_END                                      4  ~23     ~24, '%3Cbr+%2F%3E%0A'
         51        ECHO                                                     ~23
   29    52      > JMP                                                      ->53
   33    53    > > RETURN                                                   <true>
   34    54*     > RETURN                                                   null

End of function myerrorhandler

Function scale_by_log:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 48
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 48
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 41
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 16
Branch analysis from position: 9
filename:       /in/36iFH
function name:  scale_by_log
number of ops:  51
compiled vars:  !0 = $vect, !1 = $scale, !2 = $temp, !3 = $value, !4 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        INIT_FCALL                                               'is_numeric'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $5      
          5        BOOL_NOT                                         ~6      $5
          6      > JMPNZ_EX                                         ~6      ~6, ->9
          7    >   IS_SMALLER_OR_EQUAL                              ~7      !1, 0
          8        BOOL                                             ~6      ~7
          9    > > JMPZ                                                     ~6, ->16
   40    10    >   INIT_FCALL                                               'trigger_error'
         11        NOP                                                      
         12        FAST_CONCAT                                      ~8      'log%28x%29+for+x+%3C%3D+0+is+undefined%2C+you+used%3A+scale+%3D+', !1
         13        SEND_VAL                                                 ~8
         14        SEND_VAL                                                 256
         15        DO_ICALL                                                 
   43    16    >   TYPE_CHECK                                  128  ~10     !0
         17        BOOL_NOT                                         ~11     ~10
         18      > JMPZ                                                     ~11, ->24
   44    19    >   INIT_FCALL                                               'trigger_error'
         20        SEND_VAL                                                 'Incorrect+input+vector%2C+array+of+values+expected'
         21        SEND_VAL                                                 512
         22        DO_ICALL                                                 
   45    23      > RETURN                                                   null
   48    24    >   ASSIGN                                                   !2, <array>
   49    25      > FE_RESET_R                                       $14     !0, ->48
         26    > > FE_FETCH_R                                       ~15     $14, !3, ->48
         27    >   ASSIGN                                                   !4, ~15
   50    28        INIT_FCALL                                               'is_numeric'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $17     
         31        BOOL_NOT                                         ~18     $17
         32      > JMPZ                                                     ~18, ->41
   51    33    >   INIT_FCALL                                               'trigger_error'
         34        ROPE_INIT                                     3  ~20     'Value+at+position+'
         35        ROPE_ADD                                      1  ~20     ~20, !4
         36        ROPE_END                                      2  ~19     ~20, '+is+not+a+number%2C+using+0+%28zero%29'
         37        SEND_VAL                                                 ~19
         38        SEND_VAL                                                 1024
         39        DO_ICALL                                                 
   52    40        ASSIGN                                                   !3, 0
   54    41    >   INIT_FCALL                                               'log'
         42        SEND_VAR                                                 !1
         43        DO_ICALL                                         $25     
         44        MUL                                              ~26     !3, $25
         45        ASSIGN_DIM                                               !2, !4
         46        OP_DATA                                                  ~26
   49    47      > JMP                                                      ->26
         48    >   FE_FREE                                                  $14
   57    49      > RETURN                                                   !2
   58    50*     > RETURN                                                   null

End of function scale_by_log

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.16 ms | 1410 KiB | 30 Q