@@ -207,7 +207,7 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func)
207
207
} ZEND_HASH_FOREACH_END ();
208
208
}
209
209
210
- ZEND_API zend_object * zend_enum_get_case_by_value (zend_class_entry * ce , zend_long long_key , zend_string * string_key )
210
+ 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 )
211
211
{
212
212
zval * case_name_zv ;
213
213
if (ce -> enum_backing_type == IS_LONG ) {
@@ -219,7 +219,18 @@ ZEND_API zend_object *zend_enum_get_case_by_value(zend_class_entry *ce, zend_lon
219
219
}
220
220
221
221
if (case_name_zv == NULL ) {
222
- return NULL ;
222
+ if (try ) {
223
+ * result = NULL ;
224
+ return SUCCESS ;
225
+ }
226
+
227
+ if (ce -> enum_backing_type == IS_LONG ) {
228
+ zend_value_error (ZEND_LONG_FMT " is not a valid backing value for enum \"%s\"" , long_key , ZSTR_VAL (ce -> name ));
229
+ } else {
230
+ ZEND_ASSERT (ce -> enum_backing_type == IS_STRING );
231
+ zend_value_error ("\"%s\" is not a valid backing value for enum \"%s\"" , ZSTR_VAL (string_key ), ZSTR_VAL (ce -> name ));
232
+ }
233
+ return FAILURE ;
223
234
}
224
235
225
236
// TODO: We might want to store pointers to constants in backed_enum_table instead of names,
@@ -230,11 +241,12 @@ ZEND_API zend_object *zend_enum_get_case_by_value(zend_class_entry *ce, zend_lon
230
241
zval * case_zv = & c -> value ;
231
242
if (Z_TYPE_P (case_zv ) == IS_CONSTANT_AST ) {
232
243
if (zval_update_constant_ex (case_zv , c -> ce ) == FAILURE ) {
233
- return NULL ;
244
+ return FAILURE ;
234
245
}
235
246
}
236
247
237
- return Z_OBJ_P (case_zv );
248
+ * result = Z_OBJ_P (case_zv );
249
+ return SUCCESS ;
238
250
}
239
251
240
252
static void zend_enum_from_base (INTERNAL_FUNCTION_PARAMETERS , bool try )
@@ -255,24 +267,14 @@ static void zend_enum_from_base(INTERNAL_FUNCTION_PARAMETERS, bool try)
255
267
ZEND_ASSERT (ce -> enum_backing_type == IS_STRING );
256
268
}
257
269
258
- zend_object * case_obj = zend_enum_get_case_by_value (ce , long_key , string_key );
259
- // Updating of constants can fail
260
- if (EG (exception )) {
270
+ zend_object * case_obj ;
271
+ if (zend_enum_get_case_by_value (& case_obj , ce , long_key , string_key , try ) == FAILURE ) {
261
272
RETURN_THROWS ();
262
273
}
263
274
264
275
if (case_obj == NULL ) {
265
- if (try ) {
266
- RETURN_NULL ();
267
- }
268
-
269
- if (ce -> enum_backing_type == IS_LONG ) {
270
- zend_value_error (ZEND_LONG_FMT " is not a valid backing value for enum \"%s\"" , long_key , ZSTR_VAL (ce -> name ));
271
- } else {
272
- ZEND_ASSERT (ce -> enum_backing_type == IS_STRING );
273
- zend_value_error ("\"%s\" is not a valid backing value for enum \"%s\"" , ZSTR_VAL (string_key ), ZSTR_VAL (ce -> name ));
274
- }
275
- RETURN_THROWS ();
276
+ ZEND_ASSERT (try );
277
+ RETURN_NULL ();
276
278
}
277
279
278
280
ZVAL_OBJ_COPY (return_value , case_obj );
0 commit comments