3v4l.org

run code in 300+ PHP versions simultaneously
<?php // attiveremo la nostra gestione degli errori error_reporting(0); // funzione personalizzata di gestione dell'errore function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { // orario per la registrazione $dt = date("Y-m-d H:i:s (T)"); // definisce una matrice associativa con i messaggi di errore // in realtà i soli campi che saranno considerati sono // E_WARNING, E_NOTICE, E_USER_ERROR, // E_USER_WARNING and E_USER_NOTICE $errortype = array ( E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parsing Error", E_NOTICE => "Notice", E_CORE_ERROR => "Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", E_COMPILE_WARNING => "Compile Warning", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice", E_STRICT => "Runtime Notice" ); // indica gli errori per i quali fare salvare la trace delle variabili $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "<errorentry>\n"; $err .= "\t<datetime>" . $dt . "</datetime>\n"; $err .= "\t<errornum>" . $errno . "</errornum>\n"; $err .= "\t<errortype>" . $errortype[$errno] . "</errortype>\n"; $err .= "\t<errormsg>" . $errmsg . "</errormsg>\n"; $err .= "\t<scriptname>" . $filename . "</scriptname>\n"; $err .= "\t<scriptlinenum>" . $linenum . "</scriptlinenum>\n"; if (in_array($errno, $user_errors)) { $err .= "\t<vartrace>" . wddx_serialize_value($vars, "Variables") . "</vartrace>\n"; } $err .= "</errorentry>\n\n"; // for testing // echo $err; // salva nell'errorlog e invia un e-mail se vi sono errori critici error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) { mail("phpdev@example.com", "Critical User Error", $err); } } function distance($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } $d += $c2*$c2 - $c1*$c1; } return sqrt($d); } $old_error_handler = set_error_handler("userErrorHandler"); // variabile non definita, genera un warning $t = I_AM_NOT_DEFINED; // definisce dei vettori $a = array(2, 3, "foo"); $b = array(5.5, 4.3, -1.6); $c = array(1, -3); // genera un errore utente distance($c, $b) . "\n"; // un'altro errore utente distance($b, "i am not an array") . "\n"; // genera un warning distance($a, $b) . "\n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4QDh1
function name:  (null)
number of ops:  31
compiled vars:  !0 = $old_error_handler, !1 = $t, !2 = $a, !3 = $b, !4 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 0
          2        DO_ICALL                                                 
   86     3        INIT_FCALL                                               'set_error_handler'
          4        SEND_VAL                                                 'userErrorHandler'
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !0, $6
   89     7        FETCH_CONSTANT                                   ~8      'I_AM_NOT_DEFINED'
          8        ASSIGN                                                   !1, ~8
   92     9        ASSIGN                                                   !2, <array>
   93    10        ASSIGN                                                   !3, <array>
   94    11        ASSIGN                                                   !4, <array>
   97    12        INIT_FCALL                                               'distance'
         13        SEND_VAR                                                 !4
         14        SEND_VAR                                                 !3
         15        DO_FCALL                                      0  $13     
         16        CONCAT                                           ~14     $13, '%0A'
         17        FREE                                                     ~14
  100    18        INIT_FCALL                                               'distance'
         19        SEND_VAR                                                 !3
         20        SEND_VAL                                                 'i+am+not+an+array'
         21        DO_FCALL                                      0  $15     
         22        CONCAT                                           ~16     $15, '%0A'
         23        FREE                                                     ~16
  103    24        INIT_FCALL                                               'distance'
         25        SEND_VAR                                                 !2
         26        SEND_VAR                                                 !3
         27        DO_FCALL                                      0  $17     
         28        CONCAT                                           ~18     $17, '%0A'
         29        FREE                                                     ~18
  105    30      > RETURN                                                   1

Function usererrorhandler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 56
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
Branch analysis from position: 43
filename:       /in/4QDh1
function name:  userErrorHandler
number of ops:  57
compiled vars:  !0 = $errno, !1 = $errmsg, !2 = $filename, !3 = $linenum, !4 = $vars, !5 = $dt, !6 = $errortype, !7 = $user_errors, !8 = $err
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
    9     5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'Y-m-d+H%3Ai%3As+%28T%29'
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !5, $9
   15     9        ASSIGN                                                   !6, <array>
   30    10        ASSIGN                                                   !7, <array>
   32    11        ASSIGN                                                   !8, '%3Cerrorentry%3E%0A'
   33    12        CONCAT                                           ~14     '%09%3Cdatetime%3E', !5
         13        CONCAT                                           ~15     ~14, '%3C%2Fdatetime%3E%0A'
         14        ASSIGN_OP                                     8          !8, ~15
   34    15        CONCAT                                           ~17     '%09%3Cerrornum%3E', !0
         16        CONCAT                                           ~18     ~17, '%3C%2Ferrornum%3E%0A'
         17        ASSIGN_OP                                     8          !8, ~18
   35    18        FETCH_DIM_R                                      ~20     !6, !0
         19        CONCAT                                           ~21     '%09%3Cerrortype%3E', ~20
         20        CONCAT                                           ~22     ~21, '%3C%2Ferrortype%3E%0A'
         21        ASSIGN_OP                                     8          !8, ~22
   36    22        CONCAT                                           ~24     '%09%3Cerrormsg%3E', !1
         23        CONCAT                                           ~25     ~24, '%3C%2Ferrormsg%3E%0A'
         24        ASSIGN_OP                                     8          !8, ~25
   37    25        CONCAT                                           ~27     '%09%3Cscriptname%3E', !2
         26        CONCAT                                           ~28     ~27, '%3C%2Fscriptname%3E%0A'
         27        ASSIGN_OP                                     8          !8, ~28
   38    28        CONCAT                                           ~30     '%09%3Cscriptlinenum%3E', !3
         29        CONCAT                                           ~31     ~30, '%3C%2Fscriptlinenum%3E%0A'
         30        ASSIGN_OP                                     8          !8, ~31
   40    31        INIT_FCALL                                               'in_array'
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !7
         34        DO_ICALL                                         $33     
         35      > JMPZ                                                     $33, ->43
   41    36    >   INIT_FCALL_BY_NAME                                       'wddx_serialize_value'
         37        SEND_VAR_EX                                              !4
         38        SEND_VAL_EX                                              'Variables'
         39        DO_FCALL                                      0  $34     
         40        CONCAT                                           ~35     '%09%3Cvartrace%3E', $34
         41        CONCAT                                           ~36     ~35, '%3C%2Fvartrace%3E%0A'
         42        ASSIGN_OP                                     8          !8, ~36
   43    43    >   ASSIGN_OP                                     8          !8, '%3C%2Ferrorentry%3E%0A%0A'
   49    44        INIT_FCALL                                               'error_log'
         45        SEND_VAR                                                 !8
         46        SEND_VAL                                                 3
         47        SEND_VAL                                                 '%2Fusr%2Flocal%2Fphp4%2Ferror.log'
         48        DO_ICALL                                                 
   50    49        IS_EQUAL                                                 !0, 256
         50      > JMPZ                                                     ~40, ->56
   51    51    >   INIT_FCALL                                               'mail'
         52        SEND_VAL                                                 'phpdev%40example.com'
         53        SEND_VAL                                                 'Critical+User+Error'
         54        SEND_VAR                                                 !8
         55        DO_ICALL                                                 
   53    56    > > RETURN                                                   null

End of function usererrorhandler

Function distance:
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 = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 25
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 43
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 56
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 25
Branch analysis from position: 64
Branch analysis from position: 25
Branch analysis from position: 56
Branch analysis from position: 43
Branch analysis from position: 8
filename:       /in/4QDh1
function name:  distance
number of ops:  69
compiled vars:  !0 = $vect1, !1 = $vect2, !2 = $i, !3 = $c1, !4 = $c2, !5 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   58     2        TYPE_CHECK                                  128  ~6      !0
          3        BOOL_NOT                                         ~7      ~6
          4      > JMPNZ_EX                                         ~7      ~7, ->8
          5    >   TYPE_CHECK                                  128  ~8      !1
          6        BOOL_NOT                                         ~9      ~8
          7        BOOL                                             ~7      ~9
          8    > > JMPZ                                                     ~7, ->14
   59     9    >   INIT_FCALL                                               'trigger_error'
         10        SEND_VAL                                                 'Incorrect+parameters%2C+arrays+expected'
         11        SEND_VAL                                                 256
         12        DO_ICALL                                                 
   60    13      > RETURN                                                   null
   63    14    >   COUNT                                            ~11     !0
         15        COUNT                                            ~12     !1
         16        IS_NOT_EQUAL                                             ~11, ~12
         17      > JMPZ                                                     ~13, ->23
   64    18    >   INIT_FCALL                                               'trigger_error'
         19        SEND_VAL                                                 'Vectors+need+to+be+of+the+same+size'
         20        SEND_VAL                                                 256
         21        DO_ICALL                                                 
   65    22      > RETURN                                                   null
   68    23    >   ASSIGN                                                   !2, 0
         24      > JMP                                                      ->61
   69    25    >   FETCH_DIM_R                                      ~16     !0, !2
         26        ASSIGN                                                   !3, ~16
         27        FETCH_DIM_R                                      ~18     !1, !2
         28        ASSIGN                                                   !4, ~18
   70    29        ASSIGN                                                   !5, 0
   71    30        INIT_FCALL                                               'is_numeric'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $21     
         33        BOOL_NOT                                         ~22     $21
         34      > JMPZ                                                     ~22, ->43
   72    35    >   INIT_FCALL                                               'trigger_error'
         36        ROPE_INIT                                     3  ~24     'Coordinate+'
         37        ROPE_ADD                                      1  ~24     ~24, !2
         38        ROPE_END                                      2  ~23     ~24, '+in+vector+1+is+not+a+number%2C+using+zero'
         39        SEND_VAL                                                 ~23
   73    40        SEND_VAL                                                 512
         41        DO_ICALL                                                 
   74    42        ASSIGN                                                   !3, 0
   76    43    >   INIT_FCALL                                               'is_numeric'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                         $28     
         46        BOOL_NOT                                         ~29     $28
         47      > JMPZ                                                     ~29, ->56
   77    48    >   INIT_FCALL                                               'trigger_error'
         49        ROPE_INIT                                     3  ~31     'Coordinate+'
         50        ROPE_ADD                                      1  ~31     ~31, !2
         51        ROPE_END                                      2  ~30     ~31, '+in+vector+2+is+not+a+number%2C+using+zero'
         52        SEND_VAL                                                 ~30
   78    53        SEND_VAL                                                 512
         54        DO_ICALL                                                 
   79    55        ASSIGN                                                   !4, 0
   81    56    >   MUL                                              ~35     !4, !4
         57        MUL                                              ~36     !3, !3
         58        SUB                                              ~37     ~35, ~36
         59        ASSIGN_OP                                     1          !5, ~37
   68    60        PRE_INC                                                  !2
         61    >   COUNT                                            ~40     !0
         62        IS_SMALLER                                               !2, ~40
         63      > JMPNZ                                                    ~41, ->25
   83    64    >   INIT_FCALL                                               'sqrt'
         65        SEND_VAR                                                 !5
         66        DO_ICALL                                         $42     
         67      > RETURN                                                   $42
   84    68*     > RETURN                                                   null

End of function distance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.51 ms | 1410 KiB | 34 Q