3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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"; }
based on EjNPg
Output for 7.0.0 - 7.3.0alpha1
Throwing ErrorException Warning: Uncaught ErrorException: Object of class stdClass could not be converted to string in /in/rti4f:18 Stack trace: #0 [internal function]: {closure}(4096, 'Object of class...', '/in/rti4f', 18, Array) #1 /in/rti4f(18): array_diff(Array, Array) #2 {main} thrown in /in/rti4f on line 18 Fatal error: Object of class stdClass could not be converted to string in /in/rti4f on line 18
Process exited with code 255.
Output for hhvm-3.15.4
Throwing ErrorException Catched exception: Object of class stdClass could not be converted to string ---------- Throwing ErrorException Catched exception: Object of class stdClass could not be converted to string
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 1 passed to {closure}() must be an instance of int, integer given in /in/rti4f on line 4
Process exited with code 255.