3v4l.org

run code in 300+ PHP versions simultaneously
<?php define (ERROR,E_USER_WARNING); define (WARNING,E_USER_NOTICE); define (WARNING,E_USER_NOTICE); // configura il livello di restituzione errore per questo script error_reporting (FATAL | ERROR | WARNING); // funzione di gestione dell'errore function myErrorHandler ($errno, $errstr, $errfile, $errline) { switch ($errno) { 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);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "ERROR" in /in/f2VK5:5 Stack trace: #0 {main} thrown in /in/f2VK5 on line 5
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant ERROR - assumed 'ERROR' (this will throw an Error in a future version of PHP) in /in/f2VK5 on line 5 Warning: Use of undefined constant WARNING - assumed 'WARNING' (this will throw an Error in a future version of PHP) in /in/f2VK5 on line 6 Warning: Use of undefined constant FATAL - assumed 'FATAL' (this will throw an Error in a future version of PHP) in /in/f2VK5 on line 11 Warning: A non-numeric value encountered in /in/f2VK5 on line 11 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) <b>WARNING</b> [1024] Value at position 2 is not a number, using 0 (zero)<br> 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 <b>ERROR</b> [512] Incorrect input vector, array of values expected<br> NULL
Output for 7.1.0 - 7.1.20
Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/f2VK5 on line 5 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/f2VK5 on line 6 Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/f2VK5 on line 11 Warning: A non-numeric value encountered in /in/f2VK5 on line 11 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) <b>WARNING</b> [1024] Value at position 2 is not a number, using 0 (zero)<br> 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 <b>ERROR</b> [512] Incorrect input vector, array of values expected<br> NULL
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
Notice: Use of undefined constant ERROR - assumed 'ERROR' in /in/f2VK5 on line 5 Notice: Use of undefined constant WARNING - assumed 'WARNING' in /in/f2VK5 on line 6 Notice: Use of undefined constant FATAL - assumed 'FATAL' in /in/f2VK5 on line 11 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) <b>WARNING</b> [1024] Value at position 2 is not a number, using 0 (zero)<br> Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - an error <b>ERROR</b> [512] Incorrect input vector, array of values expected<br> NULL

preferences:
229.58 ms | 405 KiB | 358 Q