3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); ini_set('display_errors', 1); set_error_handler(function (int $severity, string $message, string $filename, int $line) { echo "throwing\n"; throw new ErrorException($message, 0, $severity, $filename, $line); }); $stdObject = new stdClass(); //Can't be casted to string //array_diff compares array items CASTING them to string //http://php.net/manual/en/function.array-diff.php try { array_diff([$stdObject], [$stdObject]); }catch(ErrorException $ee){ echo "Catched exception: " . $ee->getMessage() . "\n"; } echo "\n----------\n"; try { array_diff([$stdObject], [$stdObject]); }catch(ErrorException $ee){ echo "Catched exception: " . $ee->getMessage() . "\n"; }
based on 2ThvO
Output for 7.0.0 - 7.3.0beta1
throwing Warning: Uncaught ErrorException: Object of class stdClass could not be converted to string in /in/fKc22:17 Stack trace: #0 [internal function]: {closure}(4096, 'Object of class...', '/in/fKc22', 17, Array) #1 /in/fKc22(17): array_diff(Array, Array) #2 {main} thrown in /in/fKc22 on line 17 Fatal error: Object of class stdClass could not be converted to string in /in/fKc22 on line 17
Process exited with code 255.
Output for hhvm-3.15.4
throwing Catched exception: Object of class stdClass could not be converted to string ---------- throwing 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/fKc22 on line 6
Process exited with code 255.