3v4l.org

run code in 300+ PHP versions simultaneously
<?php //We set an error handler to throw an ErrorException whenever an error is triggered set_error_handler(function (int $severity, string $message, string $filename, int $line) { echo "Throwing ErrorException\n"; throw new ErrorException($message, 0, $severity, $filename, $line); }); //We're going to test this error handler passing wrong arguments to array_diff //array_diff compares array items CASTING them to string. Yes, it is retarded. //http://php.net/manual/en/function.array-diff.php //We declare an object that can't be cast to string $stdObject = new stdClass(); //First case: let's trigger an error try { array_diff([$stdObject], [$stdObject]); }catch(ErrorException $ee){ //Handler is called, exception is thrown and catched here. Yay! echo "Catched exception: " . $ee->getMessage() . "\n"; } echo "\n----------\n"; //Second case: let's trigger another slightly different error try { array_diff([$stdObject], [$stdObject]); }catch(ErrorException $ee){ //Handler is called, exception is thrown but... IT IS NOT CATCHED! echo "Catched exception: " . $ee->getMessage() . "\n"; }

preferences:
52.21 ms | 402 KiB | 5 Q