Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <=>
*/
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();

Expand Down
32 changes: 32 additions & 0 deletions tests/lang/constants/CMP.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
CMP_LT, CMP_EQ and CMP_GT ordering constants
--FILE--
<?php

echo "Check values", PHP_EOL;
var_dump(CMP_LT, CMP_EQ, CMP_GT);

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);

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 <=> return values
bool(true)
bool(true)
bool(true)
Make sure they're case-sensitive and lowercase variants aren't defined
bool(false)
bool(false)
bool(false)