Skip to content

Commit 423fc81

Browse files
committed
zend_enum: Rename try parameter to avoid conflict with C++
`try` is a keyword in C++, and as such C++ code including <zend_enum.h> fails to compile unless a workaround is in place. To resolve this, we simply rename the parameter. We choose `try_from` to make it clear that this parameter is true when the function is called from `BackedEnum::tryFrom()`. For consistency, we also rename the `try` parameter of `zend_enum_from_base()`, although that function is not exported. This issue had been reported by @oplanre, who also provided an initial PR. Closes GH-15259.
1 parent 2829065 commit 423fc81

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Zend/zend_enum.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func)
279279
} ZEND_HASH_FOREACH_END();
280280
}
281281

282-
ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try)
282+
ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try_from)
283283
{
284284
if (ce->type == ZEND_USER_CLASS && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
285285
if (zend_update_class_constants(ce) == FAILURE) {
@@ -303,7 +303,7 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
303303

304304
if (case_name_zv == NULL) {
305305
not_found:
306-
if (try) {
306+
if (try_from) {
307307
*result = NULL;
308308
return SUCCESS;
309309
}
@@ -333,7 +333,7 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
333333
return SUCCESS;
334334
}
335335

336-
static void zend_enum_from_base(INTERNAL_FUNCTION_PARAMETERS, bool try)
336+
static void zend_enum_from_base(INTERNAL_FUNCTION_PARAMETERS, bool try_from)
337337
{
338338
zend_class_entry *ce = execute_data->func->common.scope;
339339
bool release_string = false;
@@ -368,12 +368,12 @@ static void zend_enum_from_base(INTERNAL_FUNCTION_PARAMETERS, bool try)
368368
}
369369

370370
zend_object *case_obj;
371-
if (zend_enum_get_case_by_value(&case_obj, ce, long_key, string_key, try) == FAILURE) {
371+
if (zend_enum_get_case_by_value(&case_obj, ce, long_key, string_key, try_from) == FAILURE) {
372372
goto throw;
373373
}
374374

375375
if (case_obj == NULL) {
376-
ZEND_ASSERT(try);
376+
ZEND_ASSERT(try_from);
377377
goto return_null;
378378
}
379379

Zend/zend_enum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, z
4141
ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
4242
ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
4343
ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
44-
ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try);
44+
ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try_from);
4545

4646
static zend_always_inline zval *zend_enum_fetch_case_name(zend_object *zobj)
4747
{

0 commit comments

Comments
 (0)