3v4l.org

run code in 300+ PHP versions simultaneously
<?php //We enable error reporting, so we see everything //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]); }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"; }
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
---------- Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/EjNPg:26 Stack trace: #0 /in/EjNPg(26): array_diff(Array, Array) #1 {main} thrown in /in/EjNPg on line 26
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ---------- Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/EjNPg:26 Stack trace: #0 /in/EjNPg(26): array_diff(Array, Array) #1 {main} thrown in /in/EjNPg on line 26
Process exited with code 255.
Output for 7.3.16 - 7.3.33
---------- throwing Warning: Uncaught ErrorException: Object of class stdClass could not be converted to string in /in/EjNPg:26 Stack trace: #0 [internal function]: {closure}(4096, 'Object of class...', '/in/EjNPg', 26, Array) #1 /in/EjNPg(26): array_diff(Array, Array) #2 {main} thrown in /in/EjNPg on line 26 Fatal error: Object of class stdClass could not be converted to string in /in/EjNPg on line 26
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
throwing Catched exception: Object of class stdClass could not be converted to string ---------- throwing Warning: Uncaught ErrorException: Object of class stdClass could not be converted to string in /in/EjNPg:26 Stack trace: #0 [internal function]: {closure}(4096, 'Object of class...', '/in/EjNPg', 26, Array) #1 /in/EjNPg(26): array_diff(Array, Array) #2 {main} thrown in /in/EjNPg on line 26 Fatal error: Object of class stdClass could not be converted to string in /in/EjNPg on line 26
Process exited with code 255.

preferences:
170.06 ms | 402 KiB | 174 Q