3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function myErrorHandler ($errno, $errstr, $errfile, $errline) { switch ($errno) { case FATAL: echo "<b>FATAL</b> [$errno] $errstr<br>\n"; echo " Fatal error in line ".$errline." of file ".$errfile; break; case ERROR: echo "<b>ERROR</b> [$errno] $errstr<br>\n"; break; case WARNING: echo "<b>WARNING</b> [$errno] $errstr<br>\n"; break; default: echo "Unkown error type: [$errno] $errstr<br>\n"; break; } } // funzione di prova del gestore di errore 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", FATAL); if (!is_array($vect)) { trigger_error("Incorrect input vector, array of values expected", ERROR); return null; } for ($i=0; $i<count($vect); $i++) { if (!is_numeric($vect[$i])) trigger_error("Value at position $i is not a number, using 0 (zero)", WARNING); $temp[$i] = log($scale) * $vect[$i]; } return $temp; } // attiva alcuni errori, definendo prima un array misto con elementi non numerici echo "vector a\n"; $a = array(2,3,"foo",5.5,43.3,21.11); print_r($a); // genera il secondo array, generando un avviso echo "----\nvector b - a warning (b = log(PI) * a)\n"; $b = scale_by_log($a, M_PI); print_r($b); // questo è il problema, passiamo una stringa al posto di un array echo "----\nvector c - an error\n"; $c = scale_by_log("not array",2.3); var_dump($c); // errore critico, il log di zero o di un numero negativo non è definito echo "----\nvector d - fatal error\n"; $d = scale_by_log($a, -2.5); ?>
Output for 7.1.0
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 34 Warning: A non-numeric value encountered in /in/kEOgb on line 35 Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/kEOgb on line 28 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 28 NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/kEOgb on line 26 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 26 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 34 Warning: A non-numeric value encountered in /in/kEOgb on line 35
Output for hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 34 Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/kEOgb on line 28 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 28 NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/kEOgb on line 26 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 26 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be integer, string given in /in/kEOgb on line 34
Output for 5.5.0 - 5.6.28
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 34 Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/kEOgb on line 28 Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 28 NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/kEOgb on line 26 Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 26 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/kEOgb on line 34 Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 34
Output for 5.3.0 - 5.4.45
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 34 Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 28 NULL ---- vector d - fatal error Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 26 Warning: trigger_error() expects parameter 2 to be long, string given in /in/kEOgb on line 34
Output for 5.2.3 - 5.2.17
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) Warning: Invalid error type specified in /in/kEOgb on line 34 Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error Warning: Invalid error type specified in /in/kEOgb on line 28 NULL ---- vector d - fatal error Warning: Invalid error type specified in /in/kEOgb on line 26 Warning: Invalid error type specified in /in/kEOgb on line 34
Output for 4.3.0 - 5.2.2
vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a warning (b = log(PI) * a) <br /> <b>Warning</b>: Invalid error type specified in <b>/in/kEOgb</b> on line <b>34</b><br /> Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error <br /> <b>Warning</b>: Invalid error type specified in <b>/in/kEOgb</b> on line <b>28</b><br /> NULL ---- vector d - fatal error <br /> <b>Warning</b>: Invalid error type specified in <b>/in/kEOgb</b> on line <b>26</b><br /> <br /> <b>Warning</b>: Invalid error type specified in <b>/in/kEOgb</b> on line <b>34</b><br />