3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_error_handler( function( $errno, $errstr ) { printf("ERROR (%d): %s\n ==> ", $errno, $errstr); // ON ERROR RESUME NEXT; return true; } ); class string { } class int { } class float { } class bool { } function test_hh_string(HH\string $foo) { var_dump($foo); } function test_hh_int(HH\int $foo) { var_dump($foo); } function test_hh_float(HH\float $foo) { var_dump($foo); } function test_hh_bool(HH\bool $foo) { var_dump($foo); } function test_string(string $foo) { var_dump($foo); } function test_int(int $foo) { var_dump($foo); } function test_float(float $foo) { var_dump($foo); } function test_bool(bool $foo) { var_dump($foo); } print("--- CORRECT USAGE ---\n"); test_hh_string('123'); test_hh_int(123); test_hh_float(1.23); test_hh_bool(true); test_string(new string()); test_int(new int()); test_float(new float()); test_bool(new bool()); print("--- INCORRECT USAGE ---\n"); test_hh_string(new string()); test_hh_int(new int()); test_hh_float(new float()); test_hh_bool(new bool()); test_string('123'); test_int(123); test_float(1.23); test_bool(true);
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
--- CORRECT USAGE --- ERROR (4096): Argument 1 passed to test_hh_string() must be an instance of HH\string, string given, called in /in/PC85c on line 38 and defined ==> string(3) "123" ERROR (4096): Argument 1 passed to test_hh_int() must be an instance of HH\int, integer given, called in /in/PC85c on line 39 and defined ==> int(123) ERROR (4096): Argument 1 passed to test_hh_float() must be an instance of HH\float, double given, called in /in/PC85c on line 40 and defined ==> float(1.23) ERROR (4096): Argument 1 passed to test_hh_bool() must be an instance of HH\bool, boolean given, called in /in/PC85c on line 41 and defined ==> bool(true) object(string)#2 (0) { } object(int)#2 (0) { } object(float)#2 (0) { } object(bool)#2 (0) { } --- INCORRECT USAGE --- ERROR (4096): Argument 1 passed to test_hh_string() must be an instance of HH\string, instance of string given, called in /in/PC85c on line 50 and defined ==> object(string)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_int() must be an instance of HH\int, instance of int given, called in /in/PC85c on line 51 and defined ==> object(int)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_float() must be an instance of HH\float, instance of float given, called in /in/PC85c on line 52 and defined ==> object(float)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_bool() must be an instance of HH\bool, instance of bool given, called in /in/PC85c on line 53 and defined ==> object(bool)#2 (0) { } ERROR (4096): Argument 1 passed to test_string() must be an instance of string, string given, called in /in/PC85c on line 55 and defined ==> string(3) "123" ERROR (4096): Argument 1 passed to test_int() must be an instance of int, integer given, called in /in/PC85c on line 56 and defined ==> int(123) ERROR (4096): Argument 1 passed to test_float() must be an instance of float, double given, called in /in/PC85c on line 57 and defined ==> float(1.23) ERROR (4096): Argument 1 passed to test_bool() must be an instance of bool, boolean given, called in /in/PC85c on line 58 and defined ==> bool(true)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/PC85c on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/PC85c on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/PC85c on line 4
Process exited with code 255.

preferences:
241.33 ms | 1395 KiB | 163 Q