<?php
// performance hit processing non-fatal errors w/ custom error handler (e_notice, e_warning)
// affects versions 7.4.7 & 7.4.8
// array of seq. ints
$start = 3;
$number_of_values = 5000;
$seq_array = range($start, $start+$number_of_values-1);
// set error handler
function error_handler_fn($errno, $errstr, $errfile, $errline) {
$dummy = '0';
// print_r(implode(", ", Array($errno, $errstr, $errfile, $errline))."\n");
}
set_error_handler("error_handler_fn");
// array to index
$array = Array(1,2,3);
// run loop
$t1 = microtime(true);
foreach ($seq_array as $val) {
$nothing = $array[$val]; // E_NOTICE (8) - try to index array at undefined index (performance issue)
// $nothing2 = count(); // E_WARNING (2) - try to count nothing (similar performance issue)
}
$t2 = microtime(true);
$outmsg = "\n\nRun time: " . round(($t2-$t1)*1000.,2) . " milliseconds (" . phpversion() . ")";
print_r($outmsg);
?>
preferences:
14.44 ms | 402 KiB | 5 Q