com php-src: Add tests for using constants as defaults with scalar type declarations: Zend/tests/typehints/scalar_constant_defaults .phpt

From: Date: Wed, 18 Mar 2015 20:50:51 +0000
Subject: com php-src: Add tests for using constants as defaults with scalar type declarations: Zend/tests/typehints/scalar_constant_defaults .phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85685@lists.php.net to get a copy of this message
Commit: 94fe6c42faad2c814d84b5e2c807e41ef46065e0 Author: Anthony Ferrara <ircmaxell@gmail.com> Wed, 18 Mar 2015 16:50:51 -0400 Parents: 724f7118f196912a2d69a244c74dd0479e209d81 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=94fe6c42faad2c814d84b5e2c807e41ef46065e0 Log: Add tests for using constants as defaults with scalar type declarations Changed paths: A Zend/tests/typehints/scalar_constant_defaults.phpt Diff: diff --git a/Zend/tests/typehints/scalar_constant_defaults.phpt b/Zend/tests/typehints/scalar_constant_defaults.phpt new file mode 100644 index 0000000..b04c079 --- /dev/null +++ b/Zend/tests/typehints/scalar_constant_defaults.phpt @@ -0,0 +1,68 @@ +--TEST-- +Scalar type hint - default via constants +--FILE-- +<?php + +const INT_VAL = 10; +const FLOAT_VAL = 10.5; +const STRING_VAL = "this is a test"; +const INT_ADD_VAL = 10 + 15; +const FLOAT_ADD_VAL = 10.5 + 0.2; +const STRING_ADD_VAL = "this" . " is a test"; + +function int_val(int $a = INT_VAL): int { + return $a; +} + +function float_val(float $a = FLOAT_VAL): float { + return $a; +} + +function string_val(string $a = STRING_VAL): string { + return $a; +} + +function int_add_val(int $a = INT_ADD_VAL): int { + return $a; +} + +function float_add_val(float $a = FLOAT_ADD_VAL): float { + return $a; +} + +function string_add_val(string $a = STRING_ADD_VAL): string { + return $a; +} + +echo "Testing int val" . PHP_EOL; +var_dump(int_val()); + +echo "Testing float val" . PHP_EOL; +var_dump(float_val()); + +echo "Testing string val" . PHP_EOL; +var_dump(string_val()); + +echo "Testing int add val" . PHP_EOL; +var_dump(int_add_val()); + +echo "Testing float add val" . PHP_EOL; +var_dump(float_add_val()); + +echo "Testing string add val" . PHP_EOL; +var_dump(string_add_val()); + +?> +--EXPECTF-- +Testing int val +int(10) +Testing float val +float(10.5) +Testing string val +string(14) "this is a test" +Testing int add val +int(25) +Testing float add val +float(10.7) +Testing string add val +string(14) "this is a test" \ No newline at end of file

« previous php.cvs (#85685) next »