3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php restore_error_handler(); // funzione di gestione dell'errore 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; echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n"; echo "Aborting...<br>\n"; @exit(); 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; } // configura il gestore dell'errore definito dall'utente $old_error_handler = set_error_handler("myErrorHandler"); // 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] A non-numeric value encountered<br> 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant ERROR - assumed 'ERROR'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant FATAL - assumed 'FATAL'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] A non-numeric value encountered<br>
Output for 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant ERROR - assumed 'ERROR'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant FATAL - assumed 'FATAL'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be integer, string given<br>
Output for 5.3.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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be long, string given<br> 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant ERROR - assumed 'ERROR'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be long, string given<br> NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant FATAL - assumed 'FATAL'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be long, string given<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] trigger_error() expects parameter 2 to be long, string given<br>
Output for 4.3.0 - 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) Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] Invalid error type specified<br> 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 FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant ERROR - assumed 'ERROR'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] Invalid error type specified<br> NULL ---- vector d - fatal error Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant FATAL - assumed 'FATAL'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] Invalid error type specified<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [8] Use of undefined constant WARNING - assumed 'WARNING'<br> Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/DGDSF on line 8 Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/DGDSF on line 15 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/DGDSF on line 18 Unkown error type: [2] Invalid error type specified<br>