3v4l.org

run code in 300+ PHP versions simultaneously
<?php function var_export_filtered_properties(object $obj, Callable $callback, $filter = 0) { $propertiesDef = var_export($obj, true); $propertiesLines = explode(PHP_EOL, $propertiesDef); unset($propertiesLines[array_key_last($propertiesLines)], $propertiesLines[0]); $propertiesLines[] = '];'; array_unshift($propertiesLines, '$properties = ['); $desc = implode($propertiesLines, "\n"); eval($desc); $properties = array_filter($properties, function ($key) use ($callback) { return call_user_func($callback, $key); }, $filter); var_export($properties); } class MyObject { private $a = '1'; private $b = 2; public $c = 'public'; } $obj = new MyObject; var_export_filtered_properties($obj, function ($key) { return $key != 'b'; }, ARRAY_FILTER_USE_KEY);
Output for 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 - 8.3.7
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/e4hV0:13 Stack trace: #0 /in/e4hV0(13): implode(Array, '\n') #1 /in/e4hV0(30): var_export_filtered_properties(Object(MyObject), Object(Closure), 2) #2 {main} thrown in /in/e4hV0 on line 13
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 TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/e4hV0:13 Stack trace: #0 /in/e4hV0(13): implode(Array, '\n') #1 /in/e4hV0(30): var_export_filtered_properties(Object(MyObject), Object(Closure), 2) #2 {main} thrown in /in/e4hV0 on line 13
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /in/e4hV0 on line 13 array ( 'a' => '1', 'c' => 'public', )
Output for 7.3.0 - 7.3.33
array ( 'a' => '1', 'c' => 'public', )
Output for 7.2.0 - 7.2.33
Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/e4hV0:8 Stack trace: #0 /in/e4hV0(30): var_export_filtered_properties(Object(MyObject), Object(Closure), 2) #1 {main} thrown in /in/e4hV0 on line 8
Process exited with code 255.
Output for 7.1.0 - 7.1.33
Fatal error: Uncaught TypeError: Argument 1 passed to var_export_filtered_properties() must be an instance of object, instance of MyObject given, called in /in/e4hV0 on line 30 and defined in /in/e4hV0:3 Stack trace: #0 /in/e4hV0(30): var_export_filtered_properties(Object(MyObject), Object(Closure), 2) #1 {main} thrown in /in/e4hV0 on line 3
Process exited with code 255.

preferences:
173.54 ms | 402 KiB | 213 Q