3v4l.org

run code in 300+ PHP versions simultaneously
<?php $us_states = array( 'alabama', 'arkansas', 'california', 'colorado', 'connecticut', 'delaware', 'district_of_columbia', 'florida', 'georgia', 'hawaii', 'idaho', 'illinois', 'indiana', 'iowa', 'kansas', 'kentucky', 'louisiana', 'maine', 'maryland', 'massachusetts', 'michigan', 'minnesota', 'mississippi', 'missouri', 'montana', 'nebraska', 'nevada', 'new_hampshire', 'new_jersey', 'new_mexico', 'new_york', 'north_carolina', 'north_dakota', 'ohio', 'oklahoma', 'oregon', 'pennsylvania', 'rhode_island', 'south_carolina', 'south_dakota', 'tennessee', 'texas', 'utah', 'vermont', 'virginia', 'washington', 'west_virginia', 'wisconsin', 'wyoming' ); $us_states = array_map( function ( $val ) { $obj = new StdClass(); $obj->$val = $val; return $obj; }, $us_states ); // array_unshift( // array_map( // function ( $val ) { // $obj = new StdClass(); // $obj->$val = $val; // return $obj; // }, // $us_states // ), // new StdClass() // ); var_dump( array_merge( [new StdClass()], array_map( function ( $val ) { $obj = new StdClass(); $obj->$val = $val; return $obj; }, $us_states ), [new StdClass()] ) );
Output for 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/Z8HdD:42 Stack trace: #0 [internal function]: {closure}(Object(stdClass)) #1 /in/Z8HdD(39): array_map(Object(Closure), Array) #2 {main} thrown in /in/Z8HdD on line 42
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/Z8HdD:42 Stack trace: #0 [internal function]: {closure}(Object(stdClass)) #1 /in/Z8HdD(39): array_map(Object(Closure), Array) #2 {main} thrown in /in/Z8HdD on line 42
Process exited with code 255.
Output for 7.4.12 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/Z8HdD:42 Stack trace: #0 [internal function]: {closure}(Object(stdClass)) #1 /in/Z8HdD(45): array_map(Object(Closure), Array) #2 {main} thrown in /in/Z8HdD on line 42
Process exited with code 255.
Output for 7.3.24 - 7.3.33
Recoverable fatal error: Object of class stdClass could not be converted to string in /in/Z8HdD on line 42
Process exited with code 255.

preferences:
131.95 ms | 401 KiB | 118 Q