3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php set_error_handler( function( HH\int $errno, HH\string $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 hhvm-3.10.0
--- CORRECT USAGE --- string(3) "123" int(123) float(1.23) 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 string, string given ==> object(string)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_int() must be an instance of int, int given ==> object(int)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_float() must be an instance of float, float given ==> object(float)#2 (0) { } ERROR (4096): Argument 1 passed to test_hh_bool() must be an instance of bool, bool given ==> object(bool)#2 (0) { } ERROR (4096): Argument 1 passed to test_string() must be an instance of string, string given ==> string(3) "123" ERROR (4096): Argument 1 passed to test_int() must be an instance of int, int given ==> int(123) ERROR (4096): Argument 1 passed to test_float() must be an instance of float, double given ==> float(1.23) ERROR (4096): Argument 1 passed to test_bool() must be an instance of bool, bool given ==> bool(true)
Output for 5.3.0 - 5.6.2
--- CORRECT USAGE --- Catchable fatal error: Argument 1 passed to {closure}() must be an instance of HH\int, integer given in /in/iWH0N on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/iWH0N on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/iWH0N on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/iWH0N on line 4
Process exited with code 255.