From 4e911d07de7ee52e9aa4afc816078d476f6332d4 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Thu, 28 May 2015 21:17:14 +0100 Subject: [PATCH 1/2] Add ordering constants: CMP_LT, CMP_EQ, CMP_GT --- main/main.c | 7 +++++++ tests/lang/constants/CMP.phpt | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/lang/constants/CMP.phpt diff --git a/main/main.c b/main/main.c index 2d58b9c99ce86..fa48376594aba 100644 --- a/main/main.c +++ b/main/main.c @@ -2142,6 +2142,13 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS); } + /* Standard three-way comparison/ordering enumeration + * Matches compare_function() (internal), strcmp(), <=> etc. + */ + REGISTER_MAIN_LONG_CONSTANT("CMP_LT", -1, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("CMP_EQ", 0, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("CMP_GT", 1, CONST_PERSISTENT | CONST_CS); + php_output_register_constants(); php_rfc1867_register_constants(); diff --git a/tests/lang/constants/CMP.phpt b/tests/lang/constants/CMP.phpt new file mode 100644 index 0000000000000..d07e22939ab7e --- /dev/null +++ b/tests/lang/constants/CMP.phpt @@ -0,0 +1,38 @@ +--TEST-- +CMP_LT, CMP_EQ and CMP_GT ordering constants +--FILE-- + and strcmp() return values", PHP_EOL; +var_dump((1 <=> 2) === CMP_LT); +var_dump((1 <=> 1) === CMP_EQ); +var_dump((2 <=> 1) === CMP_GT); +var_dump(strcmp("a", "b") === CMP_LT); +var_dump(strcmp("a", "a") === CMP_EQ); +var_dump(strcmp("b", "a") === CMP_GT); + +echo "Make sure they're case-sensitive and lowercase variants aren't defined", PHP_EOL; +var_dump(defined("cmp_lt")); +var_dump(defined("cmp_eq")); +var_dump(defined("cmp_gt")); + +?> +--EXPECTF-- +Check values +int(-1) +int(0) +int(1) +Make sure they match <=> and strcmp() return values +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Make sure they're case-sensitive and lowercase variants aren't defined +bool(false) +bool(false) +bool(false) From b4b0ba81769f9e184dcaf953cb1ff825bb4d0341 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Thu, 28 May 2015 21:27:29 +0100 Subject: [PATCH 2/2] Do not mention strcmp(), it does not always return magnitude 1 --- main/main.c | 2 +- tests/lang/constants/CMP.phpt | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/main/main.c b/main/main.c index fa48376594aba..adaef5c85b50e 100644 --- a/main/main.c +++ b/main/main.c @@ -2143,7 +2143,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod } /* Standard three-way comparison/ordering enumeration - * Matches compare_function() (internal), strcmp(), <=> etc. + * Matches <=> */ REGISTER_MAIN_LONG_CONSTANT("CMP_LT", -1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("CMP_EQ", 0, CONST_PERSISTENT | CONST_CS); diff --git a/tests/lang/constants/CMP.phpt b/tests/lang/constants/CMP.phpt index d07e22939ab7e..56de486b33856 100644 --- a/tests/lang/constants/CMP.phpt +++ b/tests/lang/constants/CMP.phpt @@ -6,13 +6,10 @@ CMP_LT, CMP_EQ and CMP_GT ordering constants echo "Check values", PHP_EOL; var_dump(CMP_LT, CMP_EQ, CMP_GT); -echo "Make sure they match <=> and strcmp() return values", PHP_EOL; +echo "Make sure they match <=> return values", PHP_EOL; var_dump((1 <=> 2) === CMP_LT); var_dump((1 <=> 1) === CMP_EQ); var_dump((2 <=> 1) === CMP_GT); -var_dump(strcmp("a", "b") === CMP_LT); -var_dump(strcmp("a", "a") === CMP_EQ); -var_dump(strcmp("b", "a") === CMP_GT); echo "Make sure they're case-sensitive and lowercase variants aren't defined", PHP_EOL; var_dump(defined("cmp_lt")); @@ -25,10 +22,7 @@ Check values int(-1) int(0) int(1) -Make sure they match <=> and strcmp() return values -bool(true) -bool(true) -bool(true) +Make sure they match <=> return values bool(true) bool(true) bool(true)