3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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() ); $data = array( 'banana', 'cherry', 'apple' ); usort( $data, array( 'MyClass', 'sort_by_text' ) );
Output for 5.3.0 - 7.1.0
Array ( [0] => apple [1] => banana [2] => cherry ) Warning: usort() expects parameter 2 to be a valid callback, cannot access private method MyClass::sort_by_text() in /in/TURXG on line 17
Output for 5.2.5 - 5.2.17
Array ( [0] => apple [1] => banana [2] => cherry ) Warning: usort(): Invalid comparison function in /in/TURXG on line 17
Output for 5.0.5 - 5.2.4
Array ( [0] => apple [1] => banana [2] => cherry ) Warning: usort(): Invalid comparison function. in /in/TURXG on line 17
Output for 5.0.0 - 5.0.4
Array ( [0] => apple [1] => banana [2] => cherry ) Fatal error: Call to private method MyClass::sort_by_text() from context '' in /in/TURXG on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TURXG on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TURXG on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/TURXG on line 3
Process exited with code 255.