1--TEST-- 2Scalar type - default via constants 3--FILE-- 4<?php 5 6const INT_VAL = 10; 7const FLOAT_VAL = 10.5; 8const STRING_VAL = "this is a test"; 9const INT_ADD_VAL = 10 + 15; 10const FLOAT_ADD_VAL = 10.5 + 0.2; 11const STRING_ADD_VAL = "this" . " is a test"; 12const NULL_VAL = null; 13 14function int_val(int $a = INT_VAL): int { 15 return $a; 16} 17 18function float_val(float $a = FLOAT_VAL): float { 19 return $a; 20} 21 22function string_val(string $a = STRING_VAL): string { 23 return $a; 24} 25 26function int_add_val(int $a = INT_ADD_VAL): int { 27 return $a; 28} 29 30function float_add_val(float $a = FLOAT_ADD_VAL): float { 31 return $a; 32} 33 34function string_add_val(string $a = STRING_ADD_VAL): string { 35 return $a; 36} 37 38function int_val_default_null(int $a = NULL_VAL) { 39 return $a; 40} 41 42echo "Testing int val" . PHP_EOL; 43var_dump(int_val()); 44 45echo "Testing float val" . PHP_EOL; 46var_dump(float_val()); 47 48echo "Testing string val" . PHP_EOL; 49var_dump(string_val()); 50 51echo "Testing int add val" . PHP_EOL; 52var_dump(int_add_val()); 53 54echo "Testing float add val" . PHP_EOL; 55var_dump(float_add_val()); 56 57echo "Testing string add val" . PHP_EOL; 58var_dump(string_add_val()); 59 60echo "Testing int with default null constant" . PHP_EOL; 61var_dump(int_val_default_null()); 62 63echo "Testing int with null null constant" . PHP_EOL; 64var_dump(int_val_default_null(null)); 65 66?> 67--EXPECT-- 68Testing int val 69int(10) 70Testing float val 71float(10.5) 72Testing string val 73string(14) "this is a test" 74Testing int add val 75int(25) 76Testing float add val 77float(10.7) 78Testing string add val 79string(14) "this is a test" 80Testing int with default null constant 81NULL 82Testing int with null null constant 83NULL 84