You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Revert previous enum instantiation behavior and PersistableEnum trait from de5f1e5
Backed enums will be encoded as their case value. Non-backed cannot be encoded and no enums can be encoded at the root level.
Prohibit enums from implementing Persistable and Unserializable.
if (!(ZEND_CLASS_CONST_FLAGS(c) &ZEND_CLASS_CONST_IS_CASE)) {
811
-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s::%s is not an enum case", ZSTR_VAL(ce->name), case_name);
812
-
goto cleanup;
813
-
}
814
-
815
-
if (Z_TYPE(c->value) ==IS_CONSTANT_AST&&zval_update_constant_ex(&c->value, ce) ==FAILURE) {
816
-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Failed to evaluate constant expression AST for %s::%s", ZSTR_VAL(ce->name), case_name);
817
-
goto cleanup;
818
-
}
819
-
820
-
if (Z_TYPE(c->value) !=IS_OBJECT) {
821
-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Expected %s::%s to be an object, but it is: %s", ZSTR_VAL(ce->name), case_name, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(&c->value));
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Non-backed enum %s cannot be serialized for field path \"%s\"", ZSTR_VAL(Z_OBJCE_P(object)->name), path_string);
/* For the error handling that follows, we can safely assume that we
413
+
* are at the root level, since php_phongo_bson_append_object would
414
+
* have already been called for a non-root level. */
415
+
#ifPHP_VERSION_ID >= 80100
416
+
if (Z_OBJCE_P(data)->ce_flags&ZEND_ACC_ENUM) {
417
+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Enum %s cannot be serialized as a root element", ZSTR_VAL(Z_OBJCE_P(data)->name));
418
+
return;
419
+
}
420
+
#endif/* PHP_VERSION_ID >= 80100 */
421
+
392
422
if (instanceof_function(Z_OBJCE_P(data), php_phongo_type_ce)) {
393
423
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s instance %s cannot be serialized as a root element", ZSTR_VAL(php_phongo_type_ce->name), ZSTR_VAL(Z_OBJCE_P(data)->name));
0 commit comments