3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyClass { private static $data = array( 'banana', 'cherry', 'apple' ); private static function sort_by_text( $first, $second ) { return strcasecmp( $first, $second ); } public static function sorted_data() { usort( self::$data, array( __CLASS__, 'sort_by_text' ) ); return self::$data; } } print_r( MyClass::sorted_data() ); usort( array( 'banana', 'cherry', 'apple' ), array( __CLASS__, 'sort_by_text' ) );
Output for 8.3.0 - 8.3.6
Array ( [0] => apple [1] => banana [2] => cherry ) Fatal error: Uncaught Error: usort(): Argument #1 ($array) could not be passed by reference in /in/SS18e:16 Stack trace: #0 {main} thrown in /in/SS18e on line 16
Process exited with code 255.
Output for 8.1.23 - 8.1.28, 8.2.10 - 8.2.18
Array ( [0] => apple [1] => banana [2] => cherry ) Fatal error: Uncaught Error: usort(): Argument #1 ($array) cannot be passed by reference in /in/SS18e:16 Stack trace: #0 {main} thrown in /in/SS18e on line 16
Process exited with code 255.
Output for 5.3.25 - 5.3.26, 5.4.16
Fatal error: Only variables can be passed by reference in /in/IQo2N on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.24, 5.4.0 - 5.4.15
Fatal error: Only variables can be passed by reference in SS18e on line 16
Process exited with code 255.

preferences:
88.5 ms | 402 KiB | 71 Q